@@ -145,6 +145,53 @@ def test_repr_no_backslash(self):
145145 df = DataFrame (np .random .randn (10 , 4 ))
146146 self .assertTrue ('\\ ' not in repr (df ))
147147
148+ def test_expand_frame_repr (self ):
149+ import pandas .core .common as com
150+ original_in_interactive_session = com .in_interactive_session
151+ com .in_interactive_session = lambda : True
152+ line_width = 50
153+
154+ df_small = DataFrame ('hello' , [0 ], [0 ])
155+ df_wide = DataFrame ('hello' , [0 ], range (8 ))
156+
157+ def has_info_repr (df ):
158+ r = repr (df )
159+ return r .split ('\n ' )[0 ].startswith ("<class" )
160+
161+ def has_wide_repr (df ):
162+ r = repr (df )
163+ for line in r .split ('\n ' ):
164+ if line .endswith ('\\ ' ):
165+ return True
166+ return False
167+
168+ with option_context ('display.line_width' , line_width ):
169+ with option_context ('display.expand_frame_repr' , True ):
170+ self .assertFalse (has_info_repr (df_small ))
171+ self .assertFalse (has_wide_repr (df_small ))
172+ self .assertFalse (has_info_repr (df_wide ))
173+ self .assertTrue (has_wide_repr (df_wide ))
174+ with option_context ('display.max_columns' , 7 ):
175+ self .assertFalse (has_info_repr (df_small ))
176+ self .assertFalse (has_wide_repr (df_small ))
177+ self .assertTrue (has_info_repr (df_wide ))
178+ self .assertFalse (has_wide_repr (df_wide ))
179+
180+ with option_context ('display.expand_frame_repr' , False ):
181+ self .assertFalse (has_info_repr (df_small ))
182+ self .assertFalse (has_wide_repr (df_small ))
183+ self .assertTrue (has_info_repr (df_wide ))
184+ self .assertFalse (has_wide_repr (df_wide ))
185+
186+ with option_context ('display.line_width' , None ):
187+ with option_context ('display.expand_frame_repr' , True ):
188+ self .assertFalse (has_info_repr (df_small ))
189+ self .assertFalse (has_wide_repr (df_small ))
190+ self .assertFalse (has_info_repr (df_wide ))
191+ self .assertFalse (has_wide_repr (df_wide ))
192+
193+ com .in_interactive_session = original_in_interactive_session
194+
148195 def test_repr_max_columns_max_rows (self ):
149196 import pandas .core .common as com
150197 original_in_interactive_session = com .in_interactive_session
0 commit comments