Skip to content

Commit

Permalink
Remove duplicate set_categories code (#9018)
Browse files Browse the repository at this point in the history
Currently the code in `CategoricalAccessor.set_categories` are duplicates from `CategoricalColumn`. It is removed in this PR.

Authors:
  - Michael Wang (https://github.com/isVoid)

Approvers:
  - Charles Blackmon-Luca (https://github.com/charlesbluca)

URL: #9018
  • Loading branch information
isVoid authored Aug 13, 2021
1 parent 049f08a commit e25630a
Showing 1 changed file with 6 additions and 44 deletions.
50 changes: 6 additions & 44 deletions python/cudf/cudf/core/column/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,50 +526,12 @@ def set_categories(
dtype: category
Categories (2, int64): [1, 10]
"""
ordered = ordered if ordered is not None else self.ordered
new_categories = column.as_column(new_categories)

if isinstance(new_categories, CategoricalColumn):
new_categories = new_categories.categories

# when called with rename=True, the pandas behavior is
# to replace the current category values with the new
# categories.
if rename:
# enforce same length
if len(new_categories) != len(self._column.categories):
raise ValueError(
"new_categories must have the same "
"number of items as old categories"
)

out_col = column.build_categorical_column(
categories=new_categories,
codes=self._column.base_children[0],
mask=self._column.base_mask,
size=self._column.size,
offset=self._column.offset,
ordered=ordered,
)
else:
out_col = self._column
if not (type(out_col.categories) is type(new_categories)):
# If both categories are of different Column types,
# return a column full of Nulls.
out_col = _create_empty_categorical_column(
self._column,
CategoricalDtype(
categories=new_categories, ordered=ordered
),
)
elif (
not out_col._categories_equal(new_categories, ordered=ordered)
or not self.ordered == ordered
):
out_col = out_col._set_categories(
new_categories, ordered=ordered,
)
return self._return_or_inplace(out_col, inplace=inplace)
return self._return_or_inplace(
self._column.set_categories(
new_categories=new_categories, ordered=ordered, rename=rename
),
inplace=inplace,
)

def reorder_categories(
self,
Expand Down

0 comments on commit e25630a

Please sign in to comment.