@@ -935,28 +935,22 @@ def test_contains_requires_hashable_raises(self):
935935 with pytest .raises (TypeError , match = msg ):
936936 {} in idx ._engine
937937
938- def test_copy_copies_cache (self ):
939- # GH32898
938+ def test_copy_shares_cache (self ):
939+ # GH32898, GH36840
940940 idx = self .create_index ()
941941 idx .get_loc (idx [0 ]) # populates the _cache.
942942 copy = idx .copy ()
943943
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
950945
951- def test_shallow_copy_copies_cache (self ):
952- # GH32669
946+ def test_shallow_copy_shares_cache (self ):
947+ # GH32669, GH36840
953948 idx = self .create_index ()
954949 idx .get_loc (idx [0 ]) # populates the _cache.
955950 shallow_copy = idx ._shallow_copy ()
956951
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