Skip to content

Commit 8d34e9b

Browse files
committed
BUG: Regression in the display of a MultiIndexed Series with display.max_rows (GH7101)
1 parent 8a8ead6 commit 8d34e9b

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

doc/source/release.rst

+2
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ Improvements to existing features
337337
- ``GroupBy.count()`` is now implemented in Cython and is much faster for large
338338
numbers of groups (:issue:`7016`).
339339
- ``boxplot`` now supports ``layout`` keyword (:issue:`6769`)
340+
- Regression in the display of a MultiIndexed Series with ``display.max_rows`` is less than the
341+
length of the series (:issue:`7101`)
340342

341343
.. _release.bug_fixes-0.14.0:
342344

doc/source/v0.14.0.txt

+3
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ API changes
202202
Display Changes
203203
~~~~~~~~~~~~~~~
204204

205+
- Regression in the display of a MultiIndexed Series with ``display.max_rows`` is less than the
206+
length of the series (:issue:`7101`)
207+
205208
.. _whatsnew_0140.groupby:
206209

207210
Groupby API Changes

pandas/core/series.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,11 @@ def _tidy_repr(self, max_vals=20):
848848
849849
Internal function, should always return unicode string
850850
"""
851-
num = max_vals // 2
851+
if max_vals > 1:
852+
num = max_vals // 2
853+
else:
854+
num = 1
855+
max_vals = 2
852856
head = self.iloc[:num]._get_repr(print_header=True, length=False,
853857
dtype=False, name=False)
854858
tail = self.iloc[-(max_vals - num):]._get_repr(print_header=False,

pandas/tests/test_format.py

+37-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from numpy.random import randn
1414
import numpy as np
1515

16-
from pandas import DataFrame, Series, Index, _np_version_under1p7, Timestamp
16+
from pandas import DataFrame, Series, Index, _np_version_under1p7, Timestamp, MultiIndex
1717

1818
import pandas.core.format as fmt
1919
import pandas.util.testing as tm
@@ -2057,6 +2057,42 @@ def test_mixed_datetime64(self):
20572057
result = repr(df.ix[0])
20582058
self.assertTrue('2012-01-01' in result)
20592059

2060+
def test_max_multi_index_display(self):
2061+
# GH 7101
2062+
2063+
# doc example (indexing.rst)
2064+
2065+
# multi-index
2066+
arrays = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'],
2067+
['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]
2068+
tuples = list(zip(*arrays))
2069+
index = MultiIndex.from_tuples(tuples, names=['first', 'second'])
2070+
s = Series(randn(8), index=index)
2071+
2072+
with option_context("display.max_rows", 10):
2073+
self.assertEquals(len(str(s).split('\n')),10)
2074+
with option_context("display.max_rows", 3):
2075+
self.assertEquals(len(str(s).split('\n')),5)
2076+
with option_context("display.max_rows", 2):
2077+
self.assertEquals(len(str(s).split('\n')),5)
2078+
with option_context("display.max_rows", 1):
2079+
self.assertEquals(len(str(s).split('\n')),5)
2080+
with option_context("display.max_rows", 0):
2081+
self.assertEquals(len(str(s).split('\n')),10)
2082+
2083+
# index
2084+
s = Series(randn(8), None)
2085+
2086+
with option_context("display.max_rows", 10):
2087+
self.assertEquals(len(str(s).split('\n')),9)
2088+
with option_context("display.max_rows", 3):
2089+
self.assertEquals(len(str(s).split('\n')),4)
2090+
with option_context("display.max_rows", 2):
2091+
self.assertEquals(len(str(s).split('\n')),4)
2092+
with option_context("display.max_rows", 1):
2093+
self.assertEquals(len(str(s).split('\n')),4)
2094+
with option_context("display.max_rows", 0):
2095+
self.assertEquals(len(str(s).split('\n')),9)
20602096

20612097
class TestEngFormatter(tm.TestCase):
20622098
_multiprocess_can_split_ = True

0 commit comments

Comments
 (0)