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

Wrap custom iterator result #17251

Open
wants to merge 2 commits into
base: branch-24.12
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion python/cudf/cudf/pandas/_wrappers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,7 @@ def array_interface(self: _FastSlowProxy):


def custom_iter(self: _FastSlowProxy):
return iter(self._fsproxy_slow)
return _maybe_wrap_result(
iter(self._fsproxy_slow),
None, # type: ignore
)
4 changes: 3 additions & 1 deletion python/cudf/cudf/pandas/fast_slow_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,9 @@ def _maybe_wrap_result(result: Any, func: Callable, /, *args, **kwargs) -> Any:
"""
Wraps "result" in a fast-slow proxy if is a "proxiable" object.
"""
if _is_final_type(result):
if isinstance(result, (int, str, float, bool, type(None))):
return result
elif _is_final_type(result):
typ = get_final_type_map()[type(result)]
return typ._fsproxy_wrap(result, func)
elif _is_intermediate_type(result):
Expand Down
11 changes: 11 additions & 0 deletions python/cudf/cudf_pandas_tests/test_cudf_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1777,3 +1777,14 @@ def test_cudf_pandas_util_version(attrs):
assert not hasattr(pd.util, attrs)
else:
assert hasattr(pd.util, attrs)


def test_iteration_over_dataframe_dtypes_produces_proxy_objects(dataframe):
_, xdf = dataframe
xdf["b"] = xpd.IntervalIndex.from_arrays(xdf["a"], xdf["b"])
xdf["a"] = xpd.Series([1, 1, 1, 2, 3], dtype="category")
dtype_series = xdf.dtypes
for x in dtype_series:
assert is_proxy_object(x)
assert isinstance(dtype_series.iloc[0], xpd.CategoricalDtype)
assert isinstance(dtype_series.iloc[1], xpd.IntervalDtype)
Loading