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

Enable dask dispatch to cuDF's is_categorical_dtype for cuDF objects #7740

Merged
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
2 changes: 1 addition & 1 deletion conda/environments/cudf_dev_cuda10.1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dependencies:
- mypy=0.782
- typing_extensions
- pre_commit
- dask>=2.22.0
- dask>=2021.3.1
- distributed>=2.22.0
- streamz
- dlpack
Expand Down
2 changes: 1 addition & 1 deletion conda/environments/cudf_dev_cuda10.2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dependencies:
- mypy=0.782
- typing_extensions
- pre_commit
- dask>=2.22.0
- dask>=2021.3.1
- distributed>=2.22.0
- streamz
- dlpack
Expand Down
2 changes: 1 addition & 1 deletion conda/environments/cudf_dev_cuda11.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dependencies:
- mypy=0.782
- typing_extensions
- pre_commit
- dask>=2.22.0
- dask>=2021.3.1
- distributed>=2.22.0
- streamz
- dlpack
Expand Down
4 changes: 2 additions & 2 deletions conda/recipes/dask-cudf/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ requirements:
host:
- python
- cudf {{ version }}=*_{{ GIT_DESCRIBE_NUMBER }}
- dask >=2.22.0
- dask>=2021.3.1
- distributed >=2.22.0
run:
- python
- cudf {{ version }}=*_{{ GIT_DESCRIBE_NUMBER }}
- dask >=2.22.0
- dask>=2021.3.1
- distributed >=2.22.0

test:
Expand Down
13 changes: 12 additions & 1 deletion python/dask_cudf/dask_cudf/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

from dask.dataframe.categorical import categorical_dtype_dispatch
from dask.dataframe.core import get_parallel_type, make_meta, meta_nonempty
from dask.dataframe.methods import concat_dispatch, tolist_dispatch
from dask.dataframe.methods import (
concat_dispatch,
is_categorical_dtype_dispatch,
tolist_dispatch,
)
from dask.dataframe.utils import (
UNKNOWN_CATEGORIES,
_nonempty_scalar,
Expand Down Expand Up @@ -220,6 +224,13 @@ def tolist_cudf(obj):
return obj.to_arrow().to_pylist()


@is_categorical_dtype_dispatch.register(
(cudf.Series, cudf.Index, cudf.CategoricalDtype, Series)
)
def is_categorical_dtype_cudf(obj):
return cudf.utils.dtypes.is_categorical_dtype(obj)


try:

from dask.dataframe.utils import group_split_dispatch, hash_object_dispatch
Expand Down
16 changes: 16 additions & 0 deletions python/dask_cudf/dask_cudf/tests/test_dispatch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pandas as pd

from dask.dataframe.methods import is_categorical_dtype

import cudf


def test_is_categorical_dispatch():
assert is_categorical_dtype(pd.CategoricalDtype([1, 2, 3]))
assert is_categorical_dtype(cudf.CategoricalDtype([1, 2, 3]))

assert is_categorical_dtype(cudf.Series([1, 2, 3], dtype="category"))
assert is_categorical_dtype(pd.Series([1, 2, 3], dtype="category"))

assert is_categorical_dtype(pd.Index([1, 2, 3], dtype="category"))
assert is_categorical_dtype(cudf.Index([1, 2, 3], dtype="category"))
23 changes: 21 additions & 2 deletions python/dask_cudf/dask_cudf/tests/test_onehot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

from dask import dataframe as dd

import dask_cudf

import cudf

import dask_cudf


def test_get_dummies_cat():
df = pd.DataFrame({"C": [], "A": []})
Expand Down Expand Up @@ -101,3 +101,22 @@ def test_get_dummies_large():
dd.get_dummies(gddf).compute(),
check_dtype=False,
)


def test_get_dummies_categorical():
# https://github.com/rapidsai/cudf/issues/7111
gdf = cudf.DataFrame({"A": ["a", "b", "b"], "B": [1, 2, 3]})
pdf = gdf.to_pandas()

gddf = dask_cudf.from_cudf(gdf, npartitions=1)
gddf = gddf.categorize(columns=["B"])

pddf = dd.from_pandas(pdf, npartitions=1)
pddf = pddf.categorize(columns=["B"])

expect = dd.get_dummies(pddf, columns=["B"])
got = dd.get_dummies(gddf, columns=["B"])

dd.assert_eq(
expect, got,
)