|
22 | 22 | import numpy as np |
23 | 23 | import pytest |
24 | 24 |
|
25 | | -from pandas.compat import HAS_PYARROW |
26 | | - |
27 | 25 | from pandas.core.dtypes.base import StorageExtensionDtype |
28 | 26 |
|
29 | 27 | import pandas as pd |
30 | 28 | import pandas._testing as tm |
31 | 29 | from pandas.api.types import is_string_dtype |
32 | 30 | from pandas.core.arrays import ArrowStringArray |
33 | 31 | from pandas.core.arrays.string_ import StringDtype |
| 32 | +from pandas.tests.arrays.string_.test_string import string_dtype_highest_priority |
34 | 33 | from pandas.tests.extension import base |
35 | 34 |
|
36 | 35 |
|
@@ -202,10 +201,13 @@ def _cast_pointwise_result(self, op_name: str, obj, other, pointwise_result): |
202 | 201 | dtype = cast(StringDtype, tm.get_dtype(obj)) |
203 | 202 | if op_name in ["__add__", "__radd__"]: |
204 | 203 | cast_to = dtype |
| 204 | + dtype_other = tm.get_dtype(other) if not isinstance(other, str) else None |
| 205 | + if isinstance(dtype_other, StringDtype): |
| 206 | + cast_to = string_dtype_highest_priority(dtype, dtype_other) |
205 | 207 | elif dtype.na_value is np.nan: |
206 | 208 | cast_to = np.bool_ # type: ignore[assignment] |
207 | 209 | elif dtype.storage == "pyarrow": |
208 | | - cast_to = "boolean[pyarrow]" # type: ignore[assignment] |
| 210 | + cast_to = "bool[pyarrow]" # type: ignore[assignment] |
209 | 211 | else: |
210 | 212 | cast_to = "boolean" # type: ignore[assignment] |
211 | 213 | return pointwise_result.astype(cast_to) |
@@ -236,9 +238,7 @@ def test_arith_series_with_array( |
236 | 238 | if ( |
237 | 239 | using_infer_string |
238 | 240 | and all_arithmetic_operators == "__radd__" |
239 | | - and ( |
240 | | - (dtype.na_value is pd.NA) or (dtype.storage == "python" and HAS_PYARROW) |
241 | | - ) |
| 241 | + and dtype.na_value is pd.NA |
242 | 242 | ): |
243 | 243 | mark = pytest.mark.xfail( |
244 | 244 | reason="The pointwise operation result will be inferred to " |
|
0 commit comments