Skip to content

Commit 9c5a56c

Browse files
committed
better comments and tests
1 parent dcbcb1b commit 9c5a56c

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

pandas/core/indexes/multi.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -994,10 +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-
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
997+
result._cache = self._cache.copy()
998+
# GH32669
999+
if "levels" in result._cache:
1000+
del result._cache["levels"]
10011001
return result
10021002

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

pandas/tests/indexes/common.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -923,11 +923,12 @@ def test_contains_requires_hashable_raises(self):
923923
def test_shallow_copy_copies_cache(self):
924924
# GH32669
925925
idx = self.create_index()
926-
idx.get_loc(idx[0]) # initiate the _engine etc.
926+
idx.get_loc(idx[0]) # populates the _cache.
927927
shallow_copy = idx._shallow_copy()
928+
928929
# check that the shallow_copied cache is a copy of the original
929930
assert idx._cache == shallow_copy._cache
930931
assert idx._cache is not shallow_copy._cache
931-
# the cache values should reference the same objects
932+
# cache values should reference the same object
932933
for key, val in idx._cache.items():
933-
assert shallow_copy._cache[key] is val
934+
assert shallow_copy._cache[key] is val, key

pandas/tests/indexes/multi/test_names.py

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
def check_level_names(index, names):
99
assert [level.name for level in index.levels] == list(names)
10-
assert index.names == list(names)
1110

1211

1312
def test_slice_keep_name():

0 commit comments

Comments
 (0)