Skip to content

Commit 005d876

Browse files
Backport PR #54535 on branch 2.1.x (REF: Replace "pyarrow" string storage checks with variable) (#54594)
Backport PR #54535: REF: Replace "pyarrow" string storage checks with variable Co-authored-by: Patrick Hoefler <[email protected]>
1 parent 49c2f33 commit 005d876

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

pandas/conftest.py

+5
Original file line numberDiff line numberDiff line change
@@ -1996,3 +1996,8 @@ def warsaw(request) -> str:
19961996
tzinfo for Europe/Warsaw using pytz, dateutil, or zoneinfo.
19971997
"""
19981998
return request.param
1999+
2000+
2001+
@pytest.fixture()
2002+
def arrow_string_storage():
2003+
return ("pyarrow",)

pandas/tests/arrays/string_/test_string.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ def test_add(dtype):
115115
tm.assert_series_equal(result, expected)
116116

117117

118-
def test_add_2d(dtype, request):
119-
if dtype.storage == "pyarrow":
118+
def test_add_2d(dtype, request, arrow_string_storage):
119+
if dtype.storage in arrow_string_storage:
120120
reason = "Failed: DID NOT RAISE <class 'ValueError'>"
121121
mark = pytest.mark.xfail(raises=None, reason=reason)
122122
request.node.add_marker(mark)
@@ -144,8 +144,8 @@ def test_add_sequence(dtype):
144144
tm.assert_extension_array_equal(result, expected)
145145

146146

147-
def test_mul(dtype, request):
148-
if dtype.storage == "pyarrow":
147+
def test_mul(dtype, request, arrow_string_storage):
148+
if dtype.storage in arrow_string_storage:
149149
reason = "unsupported operand type(s) for *: 'ArrowStringArray' and 'int'"
150150
mark = pytest.mark.xfail(raises=NotImplementedError, reason=reason)
151151
request.node.add_marker(mark)
@@ -369,8 +369,8 @@ def test_min_max(method, skipna, dtype, request):
369369

370370
@pytest.mark.parametrize("method", ["min", "max"])
371371
@pytest.mark.parametrize("box", [pd.Series, pd.array])
372-
def test_min_max_numpy(method, box, dtype, request):
373-
if dtype.storage == "pyarrow" and box is pd.array:
372+
def test_min_max_numpy(method, box, dtype, request, arrow_string_storage):
373+
if dtype.storage in arrow_string_storage and box is pd.array:
374374
if box is pd.array:
375375
reason = "'<=' not supported between instances of 'str' and 'NoneType'"
376376
else:
@@ -384,7 +384,7 @@ def test_min_max_numpy(method, box, dtype, request):
384384
assert result == expected
385385

386386

387-
def test_fillna_args(dtype, request):
387+
def test_fillna_args(dtype, request, arrow_string_storage):
388388
# GH 37987
389389

390390
arr = pd.array(["a", pd.NA], dtype=dtype)
@@ -397,7 +397,7 @@ def test_fillna_args(dtype, request):
397397
expected = pd.array(["a", "b"], dtype=dtype)
398398
tm.assert_extension_array_equal(res, expected)
399399

400-
if dtype.storage == "pyarrow":
400+
if dtype.storage in arrow_string_storage:
401401
msg = "Invalid value '1' for dtype string"
402402
else:
403403
msg = "Cannot set non-string value '1' into a StringArray."
@@ -503,10 +503,10 @@ def test_use_inf_as_na(values, expected, dtype):
503503
tm.assert_frame_equal(result, expected)
504504

505505

506-
def test_memory_usage(dtype):
506+
def test_memory_usage(dtype, arrow_string_storage):
507507
# GH 33963
508508

509-
if dtype.storage == "pyarrow":
509+
if dtype.storage in arrow_string_storage:
510510
pytest.skip(f"not applicable for {dtype.storage}")
511511

512512
series = pd.Series(["a", "b", "c"], dtype=dtype)

pandas/tests/arrays/string_/test_string_arrow.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ def test_config_bad_storage_raises():
4949
@skip_if_no_pyarrow
5050
@pytest.mark.parametrize("chunked", [True, False])
5151
@pytest.mark.parametrize("array", ["numpy", "pyarrow"])
52-
def test_constructor_not_string_type_raises(array, chunked):
52+
def test_constructor_not_string_type_raises(array, chunked, arrow_string_storage):
5353
import pyarrow as pa
5454

55-
array = pa if array == "pyarrow" else np
55+
array = pa if array in arrow_string_storage else np
5656

5757
arr = array.array([1, 2, 3])
5858
if chunked:

pandas/tests/extension/test_string.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ def test_is_not_string_type(self, dtype):
103103

104104

105105
class TestInterface(base.BaseInterfaceTests):
106-
def test_view(self, data, request):
107-
if data.dtype.storage == "pyarrow":
106+
def test_view(self, data, request, arrow_string_storage):
107+
if data.dtype.storage in arrow_string_storage:
108108
pytest.skip(reason="2D support not implemented for ArrowStringArray")
109109
super().test_view(data)
110110

@@ -116,8 +116,8 @@ def test_from_dtype(self, data):
116116

117117

118118
class TestReshaping(base.BaseReshapingTests):
119-
def test_transpose(self, data, request):
120-
if data.dtype.storage == "pyarrow":
119+
def test_transpose(self, data, request, arrow_string_storage):
120+
if data.dtype.storage in arrow_string_storage:
121121
pytest.skip(reason="2D support not implemented for ArrowStringArray")
122122
super().test_transpose(data)
123123

@@ -127,8 +127,8 @@ class TestGetitem(base.BaseGetitemTests):
127127

128128

129129
class TestSetitem(base.BaseSetitemTests):
130-
def test_setitem_preserves_views(self, data, request):
131-
if data.dtype.storage == "pyarrow":
130+
def test_setitem_preserves_views(self, data, request, arrow_string_storage):
131+
if data.dtype.storage in arrow_string_storage:
132132
pytest.skip(reason="2D support not implemented for ArrowStringArray")
133133
super().test_setitem_preserves_views(data)
134134

0 commit comments

Comments
 (0)