Skip to content
Prev Previous commit
Next Next commit
Add tests of Series.str.fullmatch
Add tests of Series.str.fullmatch Fix formatting
  • Loading branch information
frreiss committed Mar 18, 2020
commit 7fc5fd33019cc7fee5b5017131fb1526c30855e2
26 changes: 24 additions & 2 deletions pandas/tests/test_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def assert_series_or_index_equal(left, right):
("join", (",",), {}),
("ljust", (10,), {}),
("match", ("a",), {}),
("fullmatch", ("a",), {}),
("normalize", ("NFC",), {}),
("pad", (10,), {}),
("partition", (" ",), {"expand": False}),
Expand Down Expand Up @@ -1176,9 +1177,9 @@ def test_match(self):
exp = Series([True, np.nan, False])
tm.assert_series_equal(result, exp)

values = Series(["fooBAD__barBAD", np.nan, "foo"])
values = Series(["fooBAD__barBAD", "BAD_BADleroybrown", np.nan, "foo"])
result = values.str.match(".*BAD[_]+.*BAD")
exp = Series([True, np.nan, False])
exp = Series([True, True, np.nan, False])
tm.assert_series_equal(result, exp)

# mixed
Expand Down Expand Up @@ -1208,6 +1209,27 @@ def test_match(self):
exp = Series([True, np.nan, np.nan])
tm.assert_series_equal(exp, res)

def test_fullmatch(self):
values = Series(["fooBAD__barBAD", "BAD_BADleroybrown", np.nan, "foo"])
result = values.str.fullmatch(".*BAD[_]+.*BAD")
exp = Series([True, False, np.nan, False])
tm.assert_series_equal(result, exp)

# Make sure that flags work
from re import IGNORECASE

result = values.str.fullmatch(".*Bad[_]+.*bad", flags=IGNORECASE)
tm.assert_series_equal(result, exp)

# Make sure that the new string arrays work
string_values = Series(
["fooBAD__barBAD", "BAD_BADleroybrown", np.nan, "foo"], dtype="string"
)
result = string_values.str.fullmatch(".*BAD[_]+.*BAD")
# Result is nullable boolean with StringDtype
string_exp = Series([True, False, np.nan, False], dtype="boolean")
tm.assert_series_equal(result, string_exp)

def test_extract_expand_None(self):
values = Series(["fooBAD__barBAD", np.nan, "foo"])
with pytest.raises(ValueError, match="expand must be True or False"):
Expand Down