Skip to content

Commit

Permalink
Handle ordered parameter in CategoricalIndex.__repr__ (#16683)
Browse files Browse the repository at this point in the history
Thanks @mroeschke for catching this in #16665 (comment)

This PR factors in the `ordered` parameter while generating the `repr` for `CategoricalIndex`.

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

Approvers:
  - Matthew Roeschke (https://github.com/mroeschke)

URL: #16683
  • Loading branch information
galipremsagar authored Aug 29, 2024
1 parent 9e9efcc commit f6e2355
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/cudf/cudf/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,7 @@ def __repr__(self):
pd_preprocess.dtype._categories = (
preprocess.categories.to_pandas()
)
pd_preprocess.dtype._ordered = preprocess.dtype.ordered
cats_repr = repr(pd_preprocess).split("\n")
output = "\n".join(data_repr[:-1] + cats_repr[-1:])

Expand Down
8 changes: 8 additions & 0 deletions python/cudf/cudf/tests/test_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1491,3 +1491,11 @@ def test_large_unique_categories_repr():
with utils.cudf_timeout(2, timeout_message="Failed to repr fast enough"):
actual_repr = repr(gi)
assert expected_repr == actual_repr


@pytest.mark.parametrize("ordered", [True, False])
def test_categorical_index_ordered(ordered):
pi = pd.CategoricalIndex(range(10), ordered=ordered)
gi = cudf.CategoricalIndex(range(10), ordered=ordered)

assert repr(pi) == repr(gi)

0 comments on commit f6e2355

Please sign in to comment.