Skip to content

Commit f69b893

Browse files
committed
keep cache_readonly
1 parent b22bca4 commit f69b893

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pandas/core/indexes/multi.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ def __len__(self) -> int:
690690
# --------------------------------------------------------------------
691691
# Levels Methods
692692

693-
@property
693+
@cache_readonly
694694
def levels(self):
695695
# Use cache_readonly to ensure that self.get_locs doesn't repeatedly
696696
# create new IndexEngine
@@ -994,7 +994,10 @@ def _shallow_copy(self, values=None, **kwargs):
994994
return MultiIndex.from_tuples(values, names=names, **kwargs)
995995

996996
result = self.copy(**kwargs)
997-
result._cache = self._cache.copy()
997+
cache = self._cache.copy()
998+
if "levels" in cache:
999+
cache["levels"] = FrozenList(lev._shallow_copy() for lev in cache["levels"])
1000+
result._cache = cache
9981001
return result
9991002

10001003
def _shallow_copy_with_infer(self, values, **kwargs):

0 commit comments

Comments
 (0)