Skip to content

Commit

Permalink
Merge pull request pandas-dev#3466 from y-p/more_pprint
Browse files Browse the repository at this point in the history
Fix pprint of index, summarizes according to display.max_seq_items
  • Loading branch information
y-p committed Apr 26, 2013
2 parents f8e73d3 + 69059a3 commit 5afb0eb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
4 changes: 4 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pandas 0.12.0

- When removing an object from a store, **store.remove(key)**, raises
**KeyError** if **key** is not a valid store object.
- The repr() for (Multi)Index now obeys display.max_seq_items rather
then numpy threshold print options. (GH3426_, GH3466_)

**Bug Fixes**

Expand All @@ -61,6 +63,8 @@ pandas 0.12.0
.. _GH3379: https://github.com/pydata/pandas/issues/3379
.. _GH3454: https://github.com/pydata/pandas/issues/3454
.. _GH3457: https://github.com/pydata/pandas/issues/3457
.. _GH3426: https://github.com/pydata/pandas/issues/3426
.. _GH3466: https://github.com/pydata/pandas/issues/3466
.. _GH3038: https://github.com/pydata/pandas/issues/3038
.. _GH3437: https://github.com/pydata/pandas/issues/3437
.. _GH3455: https://github.com/pydata/pandas/issues/3455
Expand Down
19 changes: 2 additions & 17 deletions pandas/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,7 @@ def __unicode__(self):
Invoked by unicode(df) in py2 only. Yields a Unicode String in both py2/py3.
"""
if len(self) > 6 and len(self) > np.get_printoptions()['threshold']:
data = self[:3].format() + ["..."] + self[-3:].format()
else:
data = self.format()

prepr = com.pprint_thing(data, escape_chars=('\t', '\r', '\n'),quote_strings=True)
prepr = com.pprint_thing(self, escape_chars=('\t', '\r', '\n'),quote_strings=True)
return '%s(%s, dtype=%s)' % (type(self).__name__, prepr, self.dtype)

def __repr__(self):
Expand Down Expand Up @@ -1504,19 +1499,9 @@ def __unicode__(self):
"""
output = 'MultiIndex\n%s'

options = np.get_printoptions()
np.set_printoptions(threshold=50)

if len(self) > 100:
values = self[:50].format() + ["..."] + self[-50:].format()
else:
values = self.format()

summary = com.pprint_thing(values, escape_chars=('\t', '\r', '\n'),
summary = com.pprint_thing(self, escape_chars=('\t', '\r', '\n'),
quote_strings=True)

np.set_printoptions(threshold=options['threshold'])

return output % summary

def __repr__(self):
Expand Down
8 changes: 5 additions & 3 deletions pandas/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import pandas.core.common as com

import pandas.util.testing as tm
import pandas.core.config as cf

from pandas.tseries.index import _to_m8
import pandas.tseries.offsets as offsets
Expand Down Expand Up @@ -895,9 +896,10 @@ def test_print_unicode_columns(self):
repr(df.columns) # should not raise UnicodeDecodeError

def test_repr_summary(self):
r = repr(pd.Index(np.arange(10000)))
self.assertTrue(len(r) < 100)
self.assertTrue("..." in r)
with cf.option_context('display.max_seq_items',10):
r = repr(pd.Index(np.arange(1000)))
self.assertTrue(len(r) < 100)
self.assertTrue("..." in r)

def test_unicode_string_with_unicode(self):
idx = Index(range(1000))
Expand Down

0 comments on commit 5afb0eb

Please sign in to comment.