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 public APIs to Access Underlying cudf and pandas Objects from cudf.pandas Proxy Objects #17629

Open
wants to merge 8 commits into
base: branch-25.02
Choose a base branch
from

Conversation

galipremsagar
Copy link
Contributor

@galipremsagar galipremsagar commented Dec 19, 2024

Description

Fixes: #17524
Fixes: rapidsai/cuml#6232
This PR introduces methods to access the real underlying cudf and pandas objects from cudf.pandas proxy objects. These methods ensure compatibility with libraries that are cudf or pandas aware.

This PR also gives a performance boost to cudf-pandas workflows, speeds from the script posted in rapidsai/cuml#6232:

branch-25.02:

cuML Label Encoder with cuDF-Pandas took 2.00794 seconds

This PR:

cuML Label Encoder with cuDF-Pandas took 0.09284 seconds

Changes:

  • Added get_gpu_object() and get_cpu_object() methods.
  • Updated faq.md with a section explaining how to use these methods.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@galipremsagar galipremsagar added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Dec 19, 2024
@galipremsagar galipremsagar self-assigned this Dec 19, 2024
@galipremsagar galipremsagar requested a review from a team as a code owner December 19, 2024 09:27
@github-actions github-actions bot added Python Affects Python cuDF API. cudf.pandas Issues specific to cudf.pandas labels Dec 19, 2024
Copy link
Contributor

@Matt711 Matt711 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this looks good to me. But I think we should add a bullet to the "Are there any limitations?" section of this faq.md . And it should describe the implications for users of cudf.pandas and third-party libraries that are "cudf aware." For example, they could get a cupy array (not a numpy array) when working with xgboost. What do you think?

@galipremsagar
Copy link
Contributor Author

@vyasr @bdice @Matt711 This is ready for another round of reviews.

@galipremsagar galipremsagar added the 3 - Ready for Review Ready for review by team label Jan 25, 2025
Copy link
Contributor

@bdice bdice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How we document this for users is probably the most important aspect of this PR. I gave some suggestions, let me know what you think.

docs/cudf/source/cudf_pandas/faq.md Outdated Show resolved Hide resolved
docs/cudf/source/cudf_pandas/faq.md Outdated Show resolved Hide resolved
docs/cudf/source/cudf_pandas/faq.md Outdated Show resolved Hide resolved
docs/cudf/source/cudf_pandas/faq.md Outdated Show resolved Hide resolved
docs/cudf/source/cudf_pandas/faq.md Show resolved Hide resolved
and (index is None or index_extracted)
and (columns is None or columns_extracted)
) and (dtype is None and copy is None):
self.__dict__.update(data.__dict__)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use _mimic_inplace instead?

@@ -451,3 +451,17 @@ def _datetime_timedelta_find_and_replace(
except TypeError:
result_col = original_column.copy(deep=True)
return result_col # type: ignore


def _extract_from_proxy(proxy, fast=True):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def _extract_from_proxy(proxy, fast=True):
def _extract_from_proxy(proxy: Any, fast: bool=True) -> tuple[Any, bool]:

def _Series_dtype(self):
# Fast-path to extract dtype from the current
# object without round-tripping through the slow<->fast
return self._fsproxy_wrapped.dtype
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little nervous to start doing this because we need to be sure the dtype between the fast and slow object are equal correct? e.g. If _fsproxy_wrapped is a pandas.Series with a the extension pandas.Float64Dtype, would that break anything?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 - Ready for Review Ready for review by team cudf.pandas Issues specific to cudf.pandas improvement Improvement / enhancement to an existing function non-breaking Non-breaking change Python Affects Python cuDF API.
Projects
Status: In Progress
5 participants