Skip to content

Commit 71908cd

Browse files
committed
PERF: significantly improve performance of MultiIndex.shape
1 parent 269d368 commit 71908cd

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

doc/source/whatsnew/v0.25.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,7 @@ Performance improvements
939939
- Improved performance by removing the need for a garbage collect when checking for ``SettingWithCopyWarning`` (:issue:`27031`)
940940
- For :meth:`to_datetime` changed default value of cache parameter to ``True`` (:issue:`26043`)
941941
- Improved performance of :class:`DatetimeIndex` and :class:`PeriodIndex` slicing given non-unique, monotonic data (:issue:`27136`).
942+
- Improved performance of :meth:`MultiIndex.shape`
942943
943944
.. _whatsnew_0250.bug_fixes:
944945

pandas/core/indexes/multi.py

+7
Original file line numberDiff line numberDiff line change
@@ -3426,6 +3426,13 @@ def isin(self, values, level=None):
34263426
else:
34273427
return np.lib.arraysetops.in1d(level_codes, sought_labels)
34283428

3429+
@property
3430+
def shape(self):
3431+
"""
3432+
Return a tuple of the shape of the underlying data.
3433+
"""
3434+
return (len(self),)
3435+
34293436

34303437
MultiIndex._add_numeric_methods_disabled()
34313438
MultiIndex._add_numeric_methods_add_sub_disabled()

0 commit comments

Comments
 (0)