From 9047ca060d3a1162f53a752086d6c7d484d34143 Mon Sep 17 00:00:00 2001 From: tp Date: Sat, 21 Mar 2020 21:16:12 +0000 Subject: [PATCH 1/2] TST: test that Index.copy copies the cache --- pandas/tests/indexes/common.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pandas/tests/indexes/common.py b/pandas/tests/indexes/common.py index 43f696e0b13db..04fbcc90da089 100644 --- a/pandas/tests/indexes/common.py +++ b/pandas/tests/indexes/common.py @@ -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() From 1f4864074b54c8ce0d72e415e9a34581dd04a9de Mon Sep 17 00:00:00 2001 From: tp Date: Sat, 21 Mar 2020 23:36:54 +0000 Subject: [PATCH 2/2] Correct github issue numbers --- pandas/tests/indexes/common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/indexes/common.py b/pandas/tests/indexes/common.py index 04fbcc90da089..1473058b2a0a9 100644 --- a/pandas/tests/indexes/common.py +++ b/pandas/tests/indexes/common.py @@ -913,7 +913,7 @@ def test_contains_requires_hashable_raises(self): {} in idx._engine def test_copy_copies_cache(self): - # GH32883 + # GH32898 idx = self.create_index() idx.get_loc(idx[0]) # populates the _cache. copy = idx.copy() @@ -926,7 +926,7 @@ def test_copy_copies_cache(self): assert copy._cache[key] is val, key def test_shallow_copy_copies_cache(self): - # GH32898 + # GH32669 idx = self.create_index() idx.get_loc(idx[0]) # populates the _cache. shallow_copy = idx._shallow_copy()