File tree Expand file tree Collapse file tree 3 files changed +19
-0
lines changed
Expand file tree Collapse file tree 3 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -190,6 +190,7 @@ Bug Fixes
190190- Bug in ``read_sql_table`` error when reading postgres table with timezone (:issue:`7139`)
191191- Bug in ``DataFrame`` slicing may not retain metadata (:issue:`9776`)
192192- 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`)
193194
194195- Bug in ``groupby.apply()`` that would raise if a passed user defined function either returned only ``None`` (for all input). (:issue:`9685`)
195196
Original file line number Diff line number Diff line change @@ -776,6 +776,9 @@ def _get_formatted_index(self, frame):
776776 formatter = fmt )
777777 else :
778778 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 ]
779782
780783 adjoined = adjoin (1 , * fmt_index ).split ('\n ' )
781784
Original file line number Diff line number Diff line change @@ -298,6 +298,21 @@ def mkframe(n):
298298 com .pprint_thing (df ._repr_fits_horizontal_ ())
299299 self .assertTrue (has_expanded_repr (df ))
300300
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+
301316 def test_auto_detect (self ):
302317 term_width , term_height = get_terminal_size ()
303318 fac = 1.05 # Arbitrary large factor to exceed term widht
You can’t perform that action at this time.
0 commit comments