Skip to content

BUG: Regression in the display of a MultiIndexed Series with display.max_rows (GH7101) #7114

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
merged 1 commit into from
May 13, 2014
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
2 changes: 2 additions & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ Improvements to existing features
- ``GroupBy.count()`` is now implemented in Cython and is much faster for large
numbers of groups (:issue:`7016`).
- ``boxplot`` now supports ``layout`` keyword (:issue:`6769`)
- Regression in the display of a MultiIndexed Series with ``display.max_rows`` is less than the
length of the series (:issue:`7101`)

.. _release.bug_fixes-0.14.0:

Expand Down
3 changes: 3 additions & 0 deletions doc/source/v0.14.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ API changes
Display Changes
~~~~~~~~~~~~~~~

- Regression in the display of a MultiIndexed Series with ``display.max_rows`` is less than the
length of the series (:issue:`7101`)

.. _whatsnew_0140.groupby:

Groupby API Changes
Expand Down
6 changes: 5 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,11 @@ def _tidy_repr(self, max_vals=20):

Internal function, should always return unicode string
"""
num = max_vals // 2
if max_vals > 1:
num = max_vals // 2
else:
num = 1
max_vals = 2
head = self.iloc[:num]._get_repr(print_header=True, length=False,
dtype=False, name=False)
tail = self.iloc[-(max_vals - num):]._get_repr(print_header=False,
Expand Down
38 changes: 37 additions & 1 deletion pandas/tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from numpy.random import randn
import numpy as np

from pandas import DataFrame, Series, Index, _np_version_under1p7, Timestamp
from pandas import DataFrame, Series, Index, _np_version_under1p7, Timestamp, MultiIndex

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

def test_max_multi_index_display(self):
# GH 7101

# doc example (indexing.rst)

# multi-index
arrays = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'],
['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]
tuples = list(zip(*arrays))
index = MultiIndex.from_tuples(tuples, names=['first', 'second'])
s = Series(randn(8), index=index)

with option_context("display.max_rows", 10):
self.assertEquals(len(str(s).split('\n')),10)
with option_context("display.max_rows", 3):
self.assertEquals(len(str(s).split('\n')),5)
with option_context("display.max_rows", 2):
self.assertEquals(len(str(s).split('\n')),5)
with option_context("display.max_rows", 1):
self.assertEquals(len(str(s).split('\n')),5)
with option_context("display.max_rows", 0):
self.assertEquals(len(str(s).split('\n')),10)

# index
s = Series(randn(8), None)

with option_context("display.max_rows", 10):
self.assertEquals(len(str(s).split('\n')),9)
with option_context("display.max_rows", 3):
self.assertEquals(len(str(s).split('\n')),4)
with option_context("display.max_rows", 2):
self.assertEquals(len(str(s).split('\n')),4)
with option_context("display.max_rows", 1):
self.assertEquals(len(str(s).split('\n')),4)
with option_context("display.max_rows", 0):
self.assertEquals(len(str(s).split('\n')),9)

class TestEngFormatter(tm.TestCase):
_multiprocess_can_split_ = True
Expand Down