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 custom getitem to cudf.pandas #17729

Draft
wants to merge 5 commits into
base: branch-25.02
Choose a base branch
from
Draft
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
18 changes: 17 additions & 1 deletion python/cudf/cudf/pandas/_wrappers/pandas.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES.
# SPDX-FileCopyrightText: Copyright (c) 2023-2025, NVIDIA CORPORATION & AFFILIATES.
# All rights reserved.
# SPDX-License-Identifier: Apache-2.0
import abc
Expand Down Expand Up @@ -35,6 +35,7 @@
_fast_slow_function_call,
_FastSlowAttribute,
_FunctionProxy,
_maybe_wrap_result,
_Unusable,
make_final_proxy_type as _make_final_proxy_type,
make_intermediate_proxy_type as _make_intermediate_proxy_type,
Expand Down Expand Up @@ -260,6 +261,17 @@ def custom_repr_html(obj):
)[0]


def custom_getitem(self, arg):
if cudf.api.types.is_scalar(arg):
return _maybe_wrap_result(self._fsproxy_slow[arg], None)
else:
return _fast_slow_function_call(
lambda self, arg: self[arg],
self,
arg,
)[0]


if ipython_shell:
# See: https://ipython.readthedocs.io/en/stable/config/integrating.html#formatters-for-third-party-types
html_formatter = ipython_shell.display_formatter.formatters["text/html"]
Expand All @@ -285,6 +297,7 @@ def custom_repr_html(obj):
"_constructor": _FastSlowAttribute("_constructor"),
"_constructor_expanddim": _FastSlowAttribute("_constructor_expanddim"),
"_accessors": set(),
"__getitem__": custom_getitem,
},
)

Expand Down Expand Up @@ -340,6 +353,7 @@ def Index__setattr__(self, name, value):
"_data": _FastSlowAttribute("_data", private=True),
"_mask": _FastSlowAttribute("_mask", private=True),
"name": _FastSlowAttribute("name"),
"__getitem__": custom_getitem,
},
)

Expand Down Expand Up @@ -418,6 +432,7 @@ def Index__setattr__(self, name, value):
"_data": _FastSlowAttribute("_data", private=True),
"_mask": _FastSlowAttribute("_mask", private=True),
"name": _FastSlowAttribute("name"),
"__getitem__": custom_getitem,
},
)

Expand Down Expand Up @@ -455,6 +470,7 @@ def Index__setattr__(self, name, value):
"_data": _FastSlowAttribute("_data", private=True),
"_mask": _FastSlowAttribute("_mask", private=True),
"name": _FastSlowAttribute("name"),
"__getitem__": custom_getitem,
},
)

Expand Down
Loading