@@ -30,3 +30,42 @@ def test_shares_memory_string():
3030
3131 obj = pd .array (["a" , "b" ], dtype = pd .ArrowDtype (pa .string ()))
3232 assert tm .shares_memory (obj , obj )
33+
34+
35+ # Unit tests for tm.shares_memory (#55372)
36+ def test_shares_memory_numpy ():
37+ arr = np .arange (10 )
38+ view = arr [:5 ]
39+ assert tm .shares_memory (arr , view )
40+ arr2 = np .arange (10 )
41+ assert not tm .shares_memory (arr , arr2 )
42+
43+
44+ def test_shares_memory_series ():
45+ arr = np .arange (10 )
46+ s = pd .Series (arr )
47+ assert tm .shares_memory (arr , s )
48+ s2 = pd .Series (np .arange (10 ))
49+ assert not tm .shares_memory (s , s2 )
50+
51+
52+ def test_shares_memory_dataframe_single_block ():
53+ arr = np .arange (10 )
54+ df = pd .DataFrame ({"a" : arr })
55+ assert tm .shares_memory (arr , df )
56+ df2 = pd .DataFrame ({"a" : np .arange (10 )})
57+ assert not tm .shares_memory (df , df2 )
58+
59+
60+ def test_shares_memory_rangeindex ():
61+ idx = pd .RangeIndex (10 )
62+ arr = np .arange (10 )
63+ assert not tm .shares_memory (idx , arr )
64+
65+
66+ def test_shares_memory_multiindex ():
67+ idx = pd .MultiIndex .from_arrays ([np .arange (10 ), np .arange (10 , 20 )])
68+ arr = idx .codes [0 ]
69+ assert tm .shares_memory (idx , arr )
70+ arr2 = np .arange (10 )
71+ assert not tm .shares_memory (idx , arr2 )
0 commit comments