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

Avoid cudf column APIs after cudf.Series disallows column inputs #6019

Merged
merged 2 commits into from
Aug 9, 2024
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
4 changes: 2 additions & 2 deletions python/cuml/cuml/dask/preprocessing/LabelEncoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ class LabelEncoder(
0 a
1 a
2 b
0 c
1 b
3 c
4 b
dtype: object
>>> client.close()
>>> cluster.close()
Expand Down
20 changes: 11 additions & 9 deletions python/cuml/cuml/preprocessing/LabelEncoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,9 @@ def transform(self, y) -> cudf.Series:

y = cudf.Series(y, dtype="category")

encoded = y.cat.set_categories(self.classes_)._column.codes
encoded = cudf.Series(encoded, index=y.index)
encoded = y.cat.set_categories(self.classes_).cat.codes

if encoded.has_nulls and self.handle_unknown == "error":
if encoded.hasnans and self.handle_unknown == "error":
raise KeyError("Attempted to encode unseen key")

return encoded
Expand All @@ -237,9 +236,9 @@ def fit_transform(self, y, z=None) -> cudf.Series:
self.dtype = y.dtype if y.dtype != cp.dtype("O") else str

y = y.astype("category")
self.classes_ = y._column.categories
self.classes_ = y.cat.categories

return cudf.Series(y._column.codes, index=y.index)
return y.cat.codes

def inverse_transform(self, y: cudf.Series) -> cudf.Series:
"""
Expand Down Expand Up @@ -275,11 +274,14 @@ def inverse_transform(self, y: cudf.Series) -> cudf.Series:

y = y.astype(self.dtype)

ran_idx = cudf.Series(cp.arange(len(self.classes_))).astype(self.dtype)

reverted = y._column.find_and_replace(ran_idx, self.classes_, False)
# TODO: Remove ._column once .replace correctly accepts cudf.Index
ran_idx = (
cudf.Index(cp.arange(len(self.classes_)))
.astype(self.dtype)
._column
)
res = y.replace(ran_idx, self.classes_)

res = cudf.Series(reverted)
return res

def get_param_names(self):
Expand Down
Loading