Skip to content

Commit

Permalink
Add a public api to get fast slow objects
Browse files Browse the repository at this point in the history
  • Loading branch information
galipremsagar committed Dec 19, 2024
1 parent dfb7c11 commit b5eea1f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/cudf/source/cudf_pandas/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@ cuDF (learn more in [this
blog](https://medium.com/rapids-ai/easy-cpu-gpu-arrays-and-dataframes-run-your-dask-code-where-youd-like-e349d92351d)) and the [RAPIDS Accelerator for Apache Spark](https://nvidia.github.io/spark-rapids/)
provides a similar configuration-based plugin for Spark.


## Recommendation for libraries that are type aware.

When working with `cudf.pandas` proxy objects, it is important to access the real underlying objects to ensure compatibility with libraries that are `cudf` or `pandas` aware. You can use the following methods to retrieve the actual `cudf` or `pandas` objects:

- `get_cudf_pandas_fast_object()`: This method returns the fast `cudf` object from the proxy.
- `get_cudf_pandas_slow_object()`: This method returns the slow `pandas` object from the proxy.

Here is an example of how to use these methods:

```python
# Assuming `proxy_obj` is a cudf.pandas proxy object
fast_obj = proxy_obj.get_cudf_pandas_fast_object()
slow_obj = proxy_obj.get_cudf_pandas_slow_object()

# Now you can use `fast_obj` and `slow_obj` with libraries that are cudf or pandas aware
```

(are-there-any-known-limitations)=
## Are there any known limitations?

Expand Down
8 changes: 8 additions & 0 deletions python/cudf/cudf/pandas/fast_slow_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ def _fsproxy_fast_to_slow(self):
return fast_to_slow(self._fsproxy_wrapped)
return self._fsproxy_wrapped

def get_cudf_pandas_fast_object(self):
return self._fsproxy_slow_to_fast()

def get_cudf_pandas_slow_object(self):
return self._fsproxy_fast_to_slow()

@property # type: ignore
def _fsproxy_state(self) -> _State:
return (
Expand All @@ -221,6 +227,8 @@ def _fsproxy_state(self) -> _State:
"_fsproxy_slow_type": slow_type,
"_fsproxy_slow_to_fast": _fsproxy_slow_to_fast,
"_fsproxy_fast_to_slow": _fsproxy_fast_to_slow,
"get_cudf_pandas_fast_object": get_cudf_pandas_fast_object,
"get_cudf_pandas_slow_object": get_cudf_pandas_slow_object,
"_fsproxy_state": _fsproxy_state,
}

Expand Down
6 changes: 6 additions & 0 deletions python/cudf/cudf_pandas_tests/test_cudf_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1885,3 +1885,9 @@ def test_dataframe_setitem():
new_df = df + 1
df[df.columns] = new_df
tm.assert_equal(df, new_df)


def test_dataframe_get_fast_slow_methods():
df = xpd.DataFrame({"a": [1, 2, 3], "b": [1, 2, 3]})
assert isinstance(df.get_cudf_pandas_fast_object(), cudf.DataFrame)
assert isinstance(df.get_cudf_pandas_slow_object(), pd.DataFrame)

0 comments on commit b5eea1f

Please sign in to comment.