Skip to content

Commit

Permalink
Add support for proxy np.flatiter objects (#16107)
Browse files Browse the repository at this point in the history
Closes #15388

Authors:
  - Matthew Murray (https://github.com/Matt711)

Approvers:
  - Matthew Roeschke (https://github.com/mroeschke)

URL: #16107
  • Loading branch information
Matt711 authored Jun 28, 2024
1 parent 673d766 commit c40e0cc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
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

0 comments on commit c40e0cc

Please sign in to comment.