diff --git a/python/cudf/cudf/core/column/categorical.py b/python/cudf/cudf/core/column/categorical.py index 9a1fab372a6..eaffc18db70 100644 --- a/python/cudf/cudf/core/column/categorical.py +++ b/python/cudf/cudf/core/column/categorical.py @@ -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( diff --git a/python/cudf/cudf/tests/test_categorical.py b/python/cudf/cudf/tests/test_categorical.py index 2c8226e4fe5..8b3d75fe59e 100644 --- a/python/cudf/cudf/tests/test_categorical.py +++ b/python/cudf/cudf/tests/test_categorical.py @@ -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)