Skip to content

Fix pprint of index, summarizes according to display.max_seq_items #3466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
3 commits merged into from Apr 26, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -60,6 +62,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