Skip to content

TST: test that the .copy method on indexes copy the cache #32898

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 22, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion pandas/tests/indexes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,8 +912,21 @@ def test_contains_requires_hashable_raises(self):
with pytest.raises(TypeError):
{} in idx._engine

def test_copy_copies_cache(self):
# GH32883
idx = self.create_index()
idx.get_loc(idx[0]) # populates the _cache.
copy = idx.copy()

# check that the copied cache is a copy of the original
assert idx._cache == copy._cache
assert idx._cache is not copy._cache
# cache values should reference the same object
for key, val in idx._cache.items():
assert copy._cache[key] is val, key

def test_shallow_copy_copies_cache(self):
# GH32669
# GH32898
idx = self.create_index()
idx.get_loc(idx[0]) # populates the _cache.
shallow_copy = idx._shallow_copy()
Expand Down