Skip to content

Commit 85069eb

Browse files
committed
Merge pull request #8609 from shoyer/MultiIndex-shape
Fix shape attribute for MultiIndex
2 parents 2737f5a + 1460552 commit 85069eb

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

doc/source/whatsnew/v0.15.1.txt

+3
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,7 @@ Experimental
4747

4848
Bug Fixes
4949
~~~~~~~~~
50+
5051
- Bug in ``cut``/``qcut`` when using ``Series`` and ``retbins=True`` (:issue:`8589`)
52+
53+
- Fix ``shape`` attribute for ``MultiIndex`` (:issue:`8609`)

pandas/core/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def transpose(self):
297297
@property
298298
def shape(self):
299299
""" return a tuple of the shape of the underlying data """
300-
return self._data.shape
300+
return self.values.shape
301301

302302
@property
303303
def ndim(self):

pandas/tests/test_index.py

+11
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ def f():
8383
pass
8484
tm.assertRaisesRegexp(ValueError,'The truth value of a',f)
8585

86+
def test_ndarray_compat_properties(self):
87+
88+
idx = self.create_index()
89+
self.assertTrue(idx.T.equals(idx))
90+
self.assertTrue(idx.transpose().equals(idx))
91+
92+
values = idx.values
93+
for prop in ['shape', 'ndim', 'size', 'itemsize', 'nbytes']:
94+
self.assertEqual(getattr(idx, prop), getattr(values, prop))
95+
96+
8697
class TestIndex(Base, tm.TestCase):
8798
_holder = Index
8899
_multiprocess_can_split_ = True

0 commit comments

Comments
 (0)