Skip to content

Commit 9047ca0

Browse files
committed
TST: test that Index.copy copies the cache
1 parent 1b49f69 commit 9047ca0

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

pandas/tests/indexes/common.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -912,8 +912,21 @@ def test_contains_requires_hashable_raises(self):
912912
with pytest.raises(TypeError):
913913
{} in idx._engine
914914

915+
def test_copy_copies_cache(self):
916+
# GH32883
917+
idx = self.create_index()
918+
idx.get_loc(idx[0]) # populates the _cache.
919+
copy = idx.copy()
920+
921+
# check that the copied cache is a copy of the original
922+
assert idx._cache == copy._cache
923+
assert idx._cache is not copy._cache
924+
# cache values should reference the same object
925+
for key, val in idx._cache.items():
926+
assert copy._cache[key] is val, key
927+
915928
def test_shallow_copy_copies_cache(self):
916-
# GH32669
929+
# GH32898
917930
idx = self.create_index()
918931
idx.get_loc(idx[0]) # populates the _cache.
919932
shallow_copy = idx._shallow_copy()

0 commit comments

Comments
 (0)