File tree 2 files changed +28
-2
lines changed
2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change 30
30
is_float_dtype ,
31
31
is_sequence ,
32
32
is_signed_integer_dtype ,
33
+ is_string_dtype ,
33
34
is_unsigned_integer_dtype ,
34
35
pandas_dtype ,
35
36
)
@@ -1055,10 +1056,18 @@ def shares_memory(left, right) -> bool:
1055
1056
if isinstance (left , pd .core .arrays .IntervalArray ):
1056
1057
return shares_memory (left ._left , right ) or shares_memory (left ._right , right )
1057
1058
1058
- if isinstance (left , ExtensionArray ) and left .dtype == "string[pyarrow]" :
1059
+ if (
1060
+ isinstance (left , ExtensionArray )
1061
+ and is_string_dtype (left .dtype )
1062
+ and left .dtype .storage in ("pyarrow" , "pyarrow_numpy" ) # type: ignore[attr-defined] # noqa: E501
1063
+ ):
1059
1064
# https://github.com/pandas-dev/pandas/pull/43930#discussion_r736862669
1060
1065
left = cast ("ArrowExtensionArray" , left )
1061
- if isinstance (right , ExtensionArray ) and right .dtype == "string[pyarrow]" :
1066
+ if (
1067
+ isinstance (right , ExtensionArray )
1068
+ and is_string_dtype (right .dtype )
1069
+ and right .dtype .storage in ("pyarrow" , "pyarrow_numpy" ) # type: ignore[attr-defined] # noqa: E501
1070
+ ):
1062
1071
right = cast ("ArrowExtensionArray" , right )
1063
1072
left_pa_data = left ._pa_array
1064
1073
right_pa_data = right ._pa_array
Original file line number Diff line number Diff line change
1
+ import pandas .util ._test_decorators as td
2
+
1
3
import pandas as pd
2
4
import pandas ._testing as tm
3
5
@@ -11,3 +13,18 @@ def test_shares_memory_interval():
11
13
assert tm .shares_memory (obj , obj [:2 ])
12
14
13
15
assert not tm .shares_memory (obj , obj ._data .copy ())
16
+
17
+
18
+ @td .skip_if_no ("pyarrow" )
19
+ def test_shares_memory_string ():
20
+ # GH#55823
21
+ import pyarrow as pa
22
+
23
+ obj = pd .array (["a" , "b" ], dtype = "string[pyarrow]" )
24
+ assert tm .shares_memory (obj , obj )
25
+
26
+ obj = pd .array (["a" , "b" ], dtype = "string[pyarrow_numpy]" )
27
+ assert tm .shares_memory (obj , obj )
28
+
29
+ obj = pd .array (["a" , "b" ], dtype = pd .ArrowDtype (pa .string ()))
30
+ assert tm .shares_memory (obj , obj )
You can’t perform that action at this time.
0 commit comments