-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests of implemented StringFunctions (#16007)
Additionally, assert that we raise during translation for an unhandled function. Authors: - Lawrence Mitchell (https://github.com/wence-) Approvers: - https://github.com/brandon-b-miller URL: #16007
- Loading branch information
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
python/cudf_polars/tests/expressions/test_stringfunction.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
import polars as pl | ||
|
||
from cudf_polars import translate_ir | ||
from cudf_polars.testing.asserts import assert_gpu_result_equal | ||
|
||
|
||
def test_supported_stringfunction_expression(): | ||
ldf = pl.LazyFrame( | ||
{ | ||
"a": ["a", "b", "cdefg", "h", "Wıth ünιcοde"], # noqa: RUF001 | ||
"b": [0, 3, 1, -1, None], | ||
} | ||
) | ||
|
||
query = ldf.select( | ||
pl.col("a").str.starts_with("Z"), | ||
pl.col("a").str.ends_with("h").alias("endswith_h"), | ||
pl.col("a").str.to_lowercase().alias("lower"), | ||
pl.col("a").str.to_uppercase().alias("upper"), | ||
) | ||
assert_gpu_result_equal(query) | ||
|
||
|
||
def test_unsupported_stringfunction(): | ||
ldf = pl.LazyFrame( | ||
{ | ||
"a": ["a", "b", "cdefg", "h", "Wıth ünιcοde"], # noqa: RUF001 | ||
"b": [0, 3, 1, -1, None], | ||
} | ||
) | ||
|
||
q = ldf.select(pl.col("a").str.count_matches("e", literal=True)) | ||
|
||
with pytest.raises(NotImplementedError): | ||
_ = translate_ir(q._ldf.visit()) |