Skip to content

Backport PR #60700 on branch 2.3.x (TST(string dtype): Resolve xfail in test_find_replace.py) #60708

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
23 changes: 6 additions & 17 deletions pandas/tests/strings/test_find_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,23 +308,12 @@ def test_startswith_endswith_validate_na(request, any_string_dtype):
dtype=any_string_dtype,
)

dtype = ser.dtype
if (isinstance(dtype, pd.StringDtype)) or dtype == np.dtype("object"):
msg = "Allowing a non-bool 'na' in obj.str.startswith is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
ser.str.startswith("kapow", na="baz")
msg = "Allowing a non-bool 'na' in obj.str.endswith is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
ser.str.endswith("bar", na="baz")
else:
# TODO(infer_string): don't surface pyarrow errors
import pyarrow as pa

msg = "Could not convert 'baz' with type str: tried to convert to boolean"
with pytest.raises(pa.lib.ArrowInvalid, match=msg):
ser.str.startswith("kapow", na="baz")
with pytest.raises(pa.lib.ArrowInvalid, match=msg):
ser.str.endswith("kapow", na="baz")
msg = "Allowing a non-bool 'na' in obj.str.startswith is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
ser.str.startswith("kapow", na="baz")
msg = "Allowing a non-bool 'na' in obj.str.endswith is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
ser.str.endswith("bar", na="baz")


@pytest.mark.filterwarnings("ignore:Downcasting object dtype arrays:FutureWarning")
Expand Down
Loading