Repository: pandas-dev/pandas

Issue:
Truncated view for MultiIndex pd.Series broken
Taking the simple example of MultiIndex Series from the docs http://pandas.pydata.org/pandas-docs/stable/indexing.html#hierarchical-indexing-multiindexc

![screenshot from 2014-05-11 23 24 02](https://cloud.githubusercontent.com/assets/832380/2939644/b62d4a02-d952-11e3-97c6-447df3f63589.png)

Constraining max_rows results in an unexpected output. 

![screenshot from 2014-05-11 23 24 26](https://cloud.githubusercontent.com/assets/832380/2939645/b62d8058-d952-11e3-98ac-5ce48d57bfae.png)

The behavior of pd.DataFrame is as expected in 0.13.1: 

![screenshot from 2014-05-11 23 27 59](https://cloud.githubusercontent.com/assets/832380/2939653/2544a50c-d953-11e3-8d18-39e8e435f1d1.png)



Discussion:
@bjonen hmm....take a stab at this?

Sure. However, the deadline for 0.14 is on Friday right? Given https://github.com/pydata/pandas/pull/7086#issuecomment-42767962 this might have to wait until the next release... 

well, since this is a regression, going to try to get this (and other PR in). (and that's for a release-candidate) anyhow.

Ok I'll take a look. 

i'll do this (if you haven't started already).....want to finalize #7086 (which IS looking good)...
fyi I added the Display Changes section to master, so rebase and you'll see it


Resolving patch:
diff --git a/pandas/core/series.py b/pandas/core/series.py
--- a/pandas/core/series.py
+++ b/pandas/core/series.py
@@ -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,


Test patch:
diff --git a/pandas/tests/test_format.py b/pandas/tests/test_format.py
--- a/pandas/tests/test_format.py
+++ b/pandas/tests/test_format.py
@@ -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
@@ -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