Skip to content

[ArrowStringArray] TST: parametrize (part) pandas/tests/strings/test_api.py #41470

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
Changes from all commits
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
32 changes: 23 additions & 9 deletions pandas/tests/strings/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
from pandas.core import strings as strings


def test_api():
def test_api(any_string_dtype):

# GH 6106, GH 9322
assert Series.str is strings.StringMethods
assert isinstance(Series([""]).str, strings.StringMethods)
assert isinstance(Series([""], dtype=any_string_dtype).str, strings.StringMethods)


def test_api_mi_raises():
Expand Down Expand Up @@ -74,18 +74,26 @@ def test_api_per_method(
reason = None
if box is Index and values.size == 0:
if method_name in ["partition", "rpartition"] and kwargs.get("expand", True):
raises = TypeError
reason = "Method cannot deal with empty Index"
elif method_name == "split" and kwargs.get("expand", None):
raises = TypeError
reason = "Split fails on empty Series when expand=True"
elif method_name == "get_dummies":
raises = ValueError
reason = "Need to fortify get_dummies corner cases"

elif box is Index and inferred_dtype == "empty" and dtype == object:
if method_name == "get_dummies":
reason = "Need to fortify get_dummies corner cases"
elif (
box is Index
and inferred_dtype == "empty"
and dtype == object
and method_name == "get_dummies"
):
raises = ValueError
reason = "Need to fortify get_dummies corner cases"

if reason is not None:
mark = pytest.mark.xfail(reason=reason)
mark = pytest.mark.xfail(raises=raises, reason=reason)
request.node.add_marker(mark)

t = box(values, dtype=dtype) # explicit dtype to avoid casting
Expand Down Expand Up @@ -117,17 +125,23 @@ def test_api_per_method(
method(*args, **kwargs)


def test_api_for_categorical(any_string_method):
def test_api_for_categorical(any_string_method, any_string_dtype, request):
# https://github.com/pandas-dev/pandas/issues/10661
s = Series(list("aabb"))

if any_string_dtype == "arrow_string":
# unsupported operand type(s) for +: 'ArrowStringArray' and 'str'
mark = pytest.mark.xfail(raises=TypeError, reason="Not Implemented")
request.node.add_marker(mark)

s = Series(list("aabb"), dtype=any_string_dtype)
s = s + " " + s
c = s.astype("category")
assert isinstance(c.str, strings.StringMethods)

method_name, args, kwargs = any_string_method

result = getattr(c.str, method_name)(*args, **kwargs)
expected = getattr(s.str, method_name)(*args, **kwargs)
expected = getattr(s.astype("object").str, method_name)(*args, **kwargs)

if isinstance(result, DataFrame):
tm.assert_frame_equal(result, expected)
Expand Down