@@ -935,28 +935,22 @@ def test_contains_requires_hashable_raises(self):
935
935
with pytest .raises (TypeError , match = msg ):
936
936
{} in idx ._engine
937
937
938
- def test_copy_copies_cache (self ):
939
- # GH32898
938
+ def test_copy_shares_cache (self ):
939
+ # GH32898, GH36840
940
940
idx = self .create_index ()
941
941
idx .get_loc (idx [0 ]) # populates the _cache.
942
942
copy = idx .copy ()
943
943
944
- # check that the copied cache is a copy of the original
945
- assert idx ._cache == copy ._cache
946
- assert idx ._cache is not copy ._cache
947
- # cache values should reference the same object
948
- for key , val in idx ._cache .items ():
949
- assert copy ._cache [key ] is val , key
944
+ assert copy ._cache is idx ._cache
950
945
951
- def test_shallow_copy_copies_cache (self ):
952
- # GH32669
946
+ def test_shallow_copy_shares_cache (self ):
947
+ # GH32669, GH36840
953
948
idx = self .create_index ()
954
949
idx .get_loc (idx [0 ]) # populates the _cache.
955
950
shallow_copy = idx ._shallow_copy ()
956
951
957
- # check that the shallow_copied cache is a copy of the original
958
- assert idx ._cache == shallow_copy ._cache
959
- assert idx ._cache is not shallow_copy ._cache
960
- # cache values should reference the same object
961
- for key , val in idx ._cache .items ():
962
- assert shallow_copy ._cache [key ] is val , key
952
+ assert shallow_copy ._cache is idx ._cache
953
+
954
+ shallow_copy = idx ._shallow_copy (idx ._data )
955
+ assert shallow_copy ._cache is not idx ._cache
956
+ assert shallow_copy ._cache == {}
0 commit comments