-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Preserve nullable dtypes for string predicates and numeric methods #24075
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
base: main
Are you sure you want to change the base?
Changes from all commits
c3491f9
e368d01
ce04208
1271a9e
abea4e1
2dff2fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,6 +66,88 @@ def test_getitem_out_of_bounds(): | |
| assert_eq(result, expected) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "dtype", | ||
| [ | ||
| pd.StringDtype(storage="python"), | ||
| pd.StringDtype(storage="pyarrow"), | ||
| pd.StringDtype(storage="pyarrow", na_value=np.nan), | ||
| pd.ArrowDtype(pa.string()), | ||
| ], | ||
| ) | ||
| @pytest.mark.parametrize( | ||
| "method,args", | ||
| [ | ||
| ("contains", ("a",)), | ||
| ("startswith", ("a",)), | ||
| ("endswith", ("a",)), | ||
| ("isdigit", ()), | ||
| ("isnumeric", ()), | ||
| ("isalnum", ()), | ||
| ], | ||
| ) | ||
| def test_string_predicate_extension_dtype(dtype, method, args): | ||
| ps = pd.Series(["a", None, "12"], dtype=dtype) | ||
| gs = cudf.from_pandas(ps) | ||
|
|
||
| expected = getattr(ps.str, method)(*args) | ||
| result = getattr(gs.str, method)(*args) | ||
|
|
||
| assert result.dtype == expected.dtype | ||
| assert_eq(result, expected) | ||
|
Comment on lines
+69
to
+97
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Add the missing dtype and input-shape cases. Add empty, all-null, and single-element fixtures to both parity tests. Add numeric-method coverage for As per coding guidelines, cover empty, all-null, single-element, and mixed-type cases in Python string-accessor tests. Also applies to: 100-120 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
|
|
||
|
|
||
| @pytest.mark.parametrize("storage", ["python", "pyarrow"]) | ||
| @pytest.mark.parametrize( | ||
| "method,args", | ||
| [ | ||
| ("match", ("a",)), | ||
| ("isalpha", ()), | ||
| ("isdecimal", ()), | ||
| ("islower", ()), | ||
| ("isupper", ()), | ||
| ("istitle", ()), | ||
| ("isspace", ()), | ||
| ], | ||
| ) | ||
| def test_string_additional_predicate_nullable_dtype(storage, method, args): | ||
| ps = pd.Series( | ||
| ["a", None, "12", "", " ", "ABC", "Abc"], | ||
| dtype=pd.StringDtype(storage=storage), | ||
| ) | ||
| gs = cudf.from_pandas(ps) | ||
|
|
||
| expected = getattr(ps.str, method)(*args) | ||
| result = getattr(gs.str, method)(*args) | ||
|
|
||
| assert result.dtype == expected.dtype | ||
| assert_eq(result, expected) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("storage", ["python", "pyarrow"]) | ||
| @pytest.mark.parametrize("data", [["aba", None, "abc"], [], [None, None]]) | ||
| @pytest.mark.parametrize( | ||
| "method,args", | ||
| [ | ||
| ("len", ()), | ||
| ("count", ("a",)), | ||
| ("find", ("a",)), | ||
| ("rfind", ("a",)), | ||
| ("index", ("a",)), | ||
| ("rindex", ("a",)), | ||
| ], | ||
| ) | ||
| def test_string_numeric_nullable_dtype(storage, data, method, args): | ||
| ps = pd.Series(data, dtype=pd.StringDtype(storage=storage)) | ||
| gs = cudf.from_pandas(ps) | ||
|
|
||
| expected = getattr(ps.str, method)(*args) | ||
| result = getattr(gs.str, method)(*args) | ||
|
|
||
| assert result.dtype == expected.dtype | ||
| assert_eq(result, expected) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("method", ["startswith", "endswith"]) | ||
| @pytest.mark.parametrize("pat", [None, (1, 2), pd.Series([1])]) | ||
| def test_startsendwith_invalid_pat(method, pat): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win
Add a benchmark for the nullable integer cast.
new_col.astype(pd.Int64Dtype())can allocate and copy a full result column for every nullablestr.lenandstr.countcall. Add a focused benchmark for both Python-backed and PyArrow-backed nullable strings.As per coding guidelines, add unit tests and unit benchmarks.
🤖 Prompt for AI Agents
Source: Coding guidelines