Skip to content

Commit

Permalink
add some test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rjzamora committed Apr 22, 2024
1 parent d5993ae commit 15a2e76
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 10 additions & 0 deletions dask/dataframe/tests/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ def test_concat_unions_categoricals():
tm.assert_frame_equal(_concat(frames5), pd.concat(frames6))


@pytest.mark.gpu
def test_clear_known_categories_cudf():
pytest.importorskip("dask_cudf")

with dask.config.set({"dataframe.backend": "cudf"}):
ddf = dd.from_dict({"a": [0, 1, 0]}, npartitions=1)
ddf["a"] = ddf["a"].astype("category")
assert not ddf["a"].cat.known


# TODO: Remove the filterwarnings below
@pytest.mark.parametrize(
"numeric_only",
Expand Down
7 changes: 4 additions & 3 deletions dask/dataframe/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
)
from dask.dataframe._compat import PANDAS_GE_150, tm # noqa: F401
from dask.dataframe.dispatch import ( # noqa : F401
is_categorical_dtype_dispatch,
make_meta,
make_meta_obj,
meta_nonempty,
Expand Down Expand Up @@ -294,11 +295,11 @@ def clear_known_categories(x, cols=None, index=True, dtype_backend=None):
for c in cols:
x[c] = x[c].cat.set_categories([UNKNOWN_CATEGORIES])
elif is_series_like(x):
if x.dtype == "category":
if is_categorical_dtype_dispatch(x.dtype):
x = x.cat.set_categories([UNKNOWN_CATEGORIES])
if index and x.index.is_categorical():
if index and is_categorical_dtype_dispatch(x.index.dtype):
x.index = x.index.set_categories([UNKNOWN_CATEGORIES])
elif x.is_categorical():
elif is_categorical_dtype_dispatch(x.dtype):
x = x.set_categories([UNKNOWN_CATEGORIES])
return x

Expand Down

0 comments on commit 15a2e76

Please sign in to comment.