Skip to content

Commit

Permalink
test: add tests for case sensitive regex in str.contains (#986)
Browse files Browse the repository at this point in the history
* add test for case sensitive contains

* fix typo in test
  • Loading branch information
LiamConnors authored Sep 17, 2024
1 parent 33f102e commit 27536fc
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions tests/expr_and_series/str/contains_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
df_polars = pl.DataFrame(data)


def test_contains(constructor: Constructor, request: pytest.FixtureRequest) -> None:
def test_contains_case_insensitive(
constructor: Constructor, request: pytest.FixtureRequest
) -> None:
if "cudf" in str(constructor):
request.applymarker(pytest.mark.xfail)

Expand All @@ -29,7 +31,9 @@ def test_contains(constructor: Constructor, request: pytest.FixtureRequest) -> N
compare_dicts(result, expected)


def test_contains_series(constructor_eager: Any, request: pytest.FixtureRequest) -> None:
def test_contains_series_case_insensitive(
constructor_eager: Any, request: pytest.FixtureRequest
) -> None:
if "cudf" in str(constructor_eager):
request.applymarker(pytest.mark.xfail)

Expand All @@ -42,3 +46,23 @@ def test_contains_series(constructor_eager: Any, request: pytest.FixtureRequest)
"case_insensitive_match": [False, False, True, True],
}
compare_dicts(result, expected)


def test_contains_case_sensitive(constructor: Constructor) -> None:
df = nw.from_native(constructor(data))
result = df.with_columns(nw.col("pets").str.contains("parrot|Dove").alias("result"))
expected = {
"pets": ["cat", "dog", "rabbit and parrot", "dove"],
"result": [False, False, True, False],
}
compare_dicts(result, expected)


def test_contains_series_case_sensitive(constructor_eager: Any) -> None:
df = nw.from_native(constructor_eager(data), eager_only=True)
result = df.with_columns(case_sensitive_match=df["pets"].str.contains("parrot|Dove"))
expected = {
"pets": ["cat", "dog", "rabbit and parrot", "dove"],
"case_sensitive_match": [False, False, True, False],
}
compare_dicts(result, expected)

0 comments on commit 27536fc

Please sign in to comment.