File tree 3 files changed +22
-0
lines changed
3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ pandas 0.9.1
43
43
- Correctly compute/box datetime64 min/max values from Series.min/max (#2083)
44
44
- Fix unstacking edge case with unrepresented groups (#2100)
45
45
- Fix Series.str failures when using pipe pattern '|' (#2119)
46
+ - Fix pretty-printing of dict entries in Series, DataFrame (#2144)
46
47
47
48
pandas 0.9.0
48
49
============
Original file line number Diff line number Diff line change @@ -1053,6 +1053,19 @@ def _pprint_seq(seq, _nest_lvl=0):
1053
1053
fmt = u"[%s]" if hasattr (seq , '__setitem__' ) else u"(%s)"
1054
1054
return fmt % ", " .join (pprint_thing (e , _nest_lvl + 1 ) for e in seq )
1055
1055
1056
+ def _pprint_dict (seq , _nest_lvl = 0 ):
1057
+ """
1058
+ internal. pprinter for iterables. you should probably use pprint_thing()
1059
+ rather then calling this directly.
1060
+ """
1061
+ fmt = u"{%s}"
1062
+ pairs = []
1063
+
1064
+ pfmt = u"%s: %s"
1065
+ for k , v in seq .items ():
1066
+ pairs .append (pfmt % (repr (k ), repr (v )))
1067
+ return fmt % ", " .join (pairs )
1068
+
1056
1069
1057
1070
def pprint_thing (thing , _nest_lvl = 0 ):
1058
1071
"""
@@ -1077,6 +1090,9 @@ def pprint_thing(thing, _nest_lvl=0):
1077
1090
from pandas .core .format import print_config
1078
1091
if thing is None :
1079
1092
result = ''
1093
+ elif (isinstance (thing , dict ) and
1094
+ _nest_lvl < print_config .pprint_nest_depth ):
1095
+ result = _pprint_dict (thing , _nest_lvl )
1080
1096
elif _is_sequence (thing ) and _nest_lvl < print_config .pprint_nest_depth :
1081
1097
result = _pprint_seq (thing , _nest_lvl )
1082
1098
else :
Original file line number Diff line number Diff line change @@ -785,6 +785,11 @@ def test_float_trim_zeros(self):
785
785
self .assert_ (('+10' in line ) or skip )
786
786
skip = False
787
787
788
+ def test_dict_entries (self ):
789
+ df = DataFrame ({'A' : [{'a' :1 , 'b' :2 }]})
790
+
791
+ val = df .to_string ()
792
+ self .assertTrue ("{'a': 1, 'b': 2}" in val )
788
793
789
794
class TestSeriesFormatting (unittest .TestCase ):
790
795
You can’t perform that action at this time.
0 commit comments