Skip to content

REF: Replace "pyarrow" string storage checks with variable #54535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pandas/tests/arrays/string_/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
arrow_string_storage = ("pyarrow",)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be put in a conftest.py instead? IMO variables are kinda hard to discover here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to use as a fixture or as a variable from conftest? Not sure how I feel about using this in every test function signature

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was thinking as a fixture. Is it needed in all these string tests currently?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in a bunch of them, inheritance makes it a bit ugly though

11 changes: 6 additions & 5 deletions pandas/tests/arrays/string_/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pandas as pd
import pandas._testing as tm
from pandas.core.arrays.string_arrow import ArrowStringArray
from pandas.tests.arrays.string_ import arrow_string_storage
from pandas.util.version import Version


Expand Down Expand Up @@ -116,7 +117,7 @@ def test_add(dtype):


def test_add_2d(dtype, request):
if dtype.storage == "pyarrow":
if dtype.storage in arrow_string_storage:
reason = "Failed: DID NOT RAISE <class 'ValueError'>"
mark = pytest.mark.xfail(raises=None, reason=reason)
request.node.add_marker(mark)
Expand Down Expand Up @@ -145,7 +146,7 @@ def test_add_sequence(dtype):


def test_mul(dtype, request):
if dtype.storage == "pyarrow":
if dtype.storage in arrow_string_storage:
reason = "unsupported operand type(s) for *: 'ArrowStringArray' and 'int'"
mark = pytest.mark.xfail(raises=NotImplementedError, reason=reason)
request.node.add_marker(mark)
Expand Down Expand Up @@ -370,7 +371,7 @@ def test_min_max(method, skipna, dtype, request):
@pytest.mark.parametrize("method", ["min", "max"])
@pytest.mark.parametrize("box", [pd.Series, pd.array])
def test_min_max_numpy(method, box, dtype, request):
if dtype.storage == "pyarrow" and box is pd.array:
if dtype.storage in arrow_string_storage and box is pd.array:
if box is pd.array:
reason = "'<=' not supported between instances of 'str' and 'NoneType'"
else:
Expand All @@ -397,7 +398,7 @@ def test_fillna_args(dtype, request):
expected = pd.array(["a", "b"], dtype=dtype)
tm.assert_extension_array_equal(res, expected)

if dtype.storage == "pyarrow":
if dtype.storage in arrow_string_storage:
msg = "Invalid value '1' for dtype string"
else:
msg = "Cannot set non-string value '1' into a StringArray."
Expand Down Expand Up @@ -506,7 +507,7 @@ def test_use_inf_as_na(values, expected, dtype):
def test_memory_usage(dtype):
# GH 33963

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

series = pd.Series(["a", "b", "c"], dtype=dtype)
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/arrays/string_/test_string_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
StringDtype,
)
from pandas.core.arrays.string_arrow import ArrowStringArray
from pandas.tests.arrays.string_ import arrow_string_storage

skip_if_no_pyarrow = pytest.mark.skipif(
pa_version_under7p0,
Expand Down Expand Up @@ -52,7 +53,7 @@ def test_config_bad_storage_raises():
def test_constructor_not_string_type_raises(array, chunked):
import pyarrow as pa

array = pa if array == "pyarrow" else np
array = pa if array in arrow_string_storage else np

arr = array.array([1, 2, 3])
if chunked:
Expand Down
8 changes: 5 additions & 3 deletions pandas/tests/extension/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
from pandas.core.arrays.string_ import StringDtype
from pandas.tests.extension import base

arrow_string_storage = ("pyarrow",)


def split_array(arr):
if arr.dtype.storage != "pyarrow":
Expand Down Expand Up @@ -104,7 +106,7 @@ def test_is_not_string_type(self, dtype):

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

Expand All @@ -117,7 +119,7 @@ def test_from_dtype(self, data):

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

Expand All @@ -128,7 +130,7 @@ class TestGetitem(base.BaseGetitemTests):

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

Expand Down