Skip to content

Commit 5afb0eb

Browse files
author
y-p
committed
Merge pull request #3466 from y-p/more_pprint
Fix pprint of index, summarizes according to display.max_seq_items
2 parents f8e73d3 + 69059a3 commit 5afb0eb

File tree

3 files changed

+11
-20
lines changed

3 files changed

+11
-20
lines changed

RELEASE.rst

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ pandas 0.12.0
4242

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

4648
**Bug Fixes**
4749

@@ -61,6 +63,8 @@ pandas 0.12.0
6163
.. _GH3379: https://github.com/pydata/pandas/issues/3379
6264
.. _GH3454: https://github.com/pydata/pandas/issues/3454
6365
.. _GH3457: https://github.com/pydata/pandas/issues/3457
66+
.. _GH3426: https://github.com/pydata/pandas/issues/3426
67+
.. _GH3466: https://github.com/pydata/pandas/issues/3466
6468
.. _GH3038: https://github.com/pydata/pandas/issues/3038
6569
.. _GH3437: https://github.com/pydata/pandas/issues/3437
6670
.. _GH3455: https://github.com/pydata/pandas/issues/3455

pandas/core/index.py

+2-17
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,7 @@ def __unicode__(self):
170170
171171
Invoked by unicode(df) in py2 only. Yields a Unicode String in both py2/py3.
172172
"""
173-
if len(self) > 6 and len(self) > np.get_printoptions()['threshold']:
174-
data = self[:3].format() + ["..."] + self[-3:].format()
175-
else:
176-
data = self.format()
177-
178-
prepr = com.pprint_thing(data, escape_chars=('\t', '\r', '\n'),quote_strings=True)
173+
prepr = com.pprint_thing(self, escape_chars=('\t', '\r', '\n'),quote_strings=True)
179174
return '%s(%s, dtype=%s)' % (type(self).__name__, prepr, self.dtype)
180175

181176
def __repr__(self):
@@ -1504,19 +1499,9 @@ def __unicode__(self):
15041499
"""
15051500
output = 'MultiIndex\n%s'
15061501

1507-
options = np.get_printoptions()
1508-
np.set_printoptions(threshold=50)
1509-
1510-
if len(self) > 100:
1511-
values = self[:50].format() + ["..."] + self[-50:].format()
1512-
else:
1513-
values = self.format()
1514-
1515-
summary = com.pprint_thing(values, escape_chars=('\t', '\r', '\n'),
1502+
summary = com.pprint_thing(self, escape_chars=('\t', '\r', '\n'),
15161503
quote_strings=True)
15171504

1518-
np.set_printoptions(threshold=options['threshold'])
1519-
15201505
return output % summary
15211506

15221507
def __repr__(self):

pandas/tests/test_index.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import pandas.core.common as com
1818

1919
import pandas.util.testing as tm
20+
import pandas.core.config as cf
2021

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

897898
def test_repr_summary(self):
898-
r = repr(pd.Index(np.arange(10000)))
899-
self.assertTrue(len(r) < 100)
900-
self.assertTrue("..." in r)
899+
with cf.option_context('display.max_seq_items',10):
900+
r = repr(pd.Index(np.arange(1000)))
901+
self.assertTrue(len(r) < 100)
902+
self.assertTrue("..." in r)
901903

902904
def test_unicode_string_with_unicode(self):
903905
idx = Index(range(1000))

0 commit comments

Comments
 (0)