Skip to content

Commit

Permalink
Fix setting of categories order when dtype is passed to a `Categori…
Browse files Browse the repository at this point in the history
…calColumn` (#13955)

closes #13947 

This PR fixes the setting of categories in the appropriate order when a dtype with the same categories but of mismatching order is passed.

Authors:
  - GALI PREM SAGAR (https://github.com/galipremsagar)

Approvers:
  - Lawrence Mitchell (https://github.com/wence-)

URL: #13955
  • Loading branch information
galipremsagar authored Aug 25, 2023
1 parent 6095a92 commit 384b33f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/column/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ def set_categories(
),
)
elif (
not out_col._categories_equal(new_categories, ordered=ordered)
not out_col._categories_equal(new_categories, ordered=True)
or not self.ordered == ordered
):
out_col = out_col._set_categories(
Expand Down
10 changes: 10 additions & 0 deletions python/cudf/cudf/tests/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,3 +926,13 @@ def test_categorical_string_index_contains(data, value):
pidx = idx.to_pandas()

assert_eq(value in idx, value in pidx)


def test_categorical_index_with_dtype():
dtype = cudf.CategoricalDtype(categories=["a", "z", "c"])
gi = cudf.Index(["z", "c", "a"], dtype=dtype)
pi = pd.Index(["z", "c", "a"], dtype=dtype.to_pandas())

assert_eq(gi, pi)
assert_eq(gi.dtype, pi.dtype)
assert_eq(gi.dtype.categories, pi.dtype.categories)

0 comments on commit 384b33f

Please sign in to comment.