File tree 3 files changed +19
-0
lines changed
3 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -190,6 +190,7 @@ Bug Fixes
190
190
- Bug in ``read_sql_table`` error when reading postgres table with timezone (:issue:`7139`)
191
191
- Bug in ``DataFrame`` slicing may not retain metadata (:issue:`9776`)
192
192
- Bug where ``TimdeltaIndex`` were not properly serialized in fixed ``HDFStore`` (:issue:`9635`)
193
+ - Bug in ``DataFrameFormatter._get_formatted_index`` with not applying ``max_colwidth`` to the ``DataFrame`` index (:issue:`7856`)
193
194
194
195
- Bug in ``groupby.apply()`` that would raise if a passed user defined function either returned only ``None`` (for all input). (:issue:`9685`)
195
196
Original file line number Diff line number Diff line change @@ -776,6 +776,9 @@ def _get_formatted_index(self, frame):
776
776
formatter = fmt )
777
777
else :
778
778
fmt_index = [index .format (name = show_index_names , formatter = fmt )]
779
+ fmt_index = [tuple (_make_fixed_width (
780
+ list (x ), justify = 'left' , minimum = (self .col_space or 0 )))
781
+ for x in fmt_index ]
779
782
780
783
adjoined = adjoin (1 , * fmt_index ).split ('\n ' )
781
784
Original file line number Diff line number Diff line change @@ -298,6 +298,21 @@ def mkframe(n):
298
298
com .pprint_thing (df ._repr_fits_horizontal_ ())
299
299
self .assertTrue (has_expanded_repr (df ))
300
300
301
+ def test_str_max_colwidth (self ):
302
+ # GH 7856
303
+ df = pd .DataFrame ([{'a' : 'foo' , 'b' : 'bar' ,
304
+ 'c' : 'uncomfortably long line with lots of stuff' ,
305
+ 'd' : 1 },
306
+ {'a' : 'foo' , 'b' : 'bar' , 'c' : 'stuff' , 'd' : 1 }])
307
+ df .set_index (['a' , 'b' , 'c' ])
308
+ self .assertTrue (str (df ) == ' a b c d\n '
309
+ '0 foo bar uncomfortably long line with lots of stuff 1\n '
310
+ '1 foo bar stuff 1' )
311
+ with option_context ('max_colwidth' , 20 ):
312
+ self .assertTrue (str (df ) == ' a b c d\n '
313
+ '0 foo bar uncomfortably lo... 1\n '
314
+ '1 foo bar stuff 1' )
315
+
301
316
def test_auto_detect (self ):
302
317
term_width , term_height = get_terminal_size ()
303
318
fac = 1.05 # Arbitrary large factor to exceed term widht
You can’t perform that action at this time.
0 commit comments