Skip to content
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

Add support for proxy np.flatiter objects #16107

Merged
merged 5 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions python/cudf/cudf/pandas/_wrappers/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,19 @@ def wrap_ndarray(cls, arr: cupy.ndarray | numpy.ndarray, constructor):
},
)


flatiter = make_final_proxy_type(
"flatiter",
cupy.flatiter,
numpy.flatiter,
fast_to_slow=lambda fast: cupy.asnumpy(fast.base).flat,
slow_to_fast=lambda slow: cupy.asarray(slow).flat,
additional_attributes={
"__array__": array_method,
},
)


# Mapping flags between slow and fast types
_ndarray_flags = make_intermediate_proxy_type(
"_ndarray_flags",
Expand Down
10 changes: 10 additions & 0 deletions python/cudf/cudf_pandas_tests/test_cudf_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,16 @@ def test_is_proxy_object():
assert not is_proxy_object(s2)


def test_numpy_cupy_flatiter(series):
cp = pytest.importorskip("cupy")

_, s = series
arr = s.values

assert type(arr.flat._fsproxy_fast) == cp.flatiter
assert type(arr.flat._fsproxy_slow) == np.flatiter


def test_arrow_string_arrays():
cu_s = xpd.Series(["a", "b", "c"])
pd_s = pd.Series(["a", "b", "c"])
Expand Down
Loading