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

Refactor CategoricalIndex.__init__, make .ordered and .categories properties from the CategoricalDtype #14979

Closed
wants to merge 4 commits into from

Conversation

mroeschke
Copy link
Contributor

Description

In pandas, .ordered and .categories are defined on the CategoricalDtype and are not settable. Additionally, ensuring that they are only defined on the dtype and not also on the column so they don't go out-of-sync

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@mroeschke mroeschke added Python Affects Python cuDF API. improvement Improvement / enhancement to an existing function breaking Breaking change labels Feb 6, 2024
@mroeschke mroeschke requested a review from a team as a code owner February 6, 2024 22:14
Copy link
Contributor

@bdice bdice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple comments. What is your merge plan for this? Should we test with other RAPIDS libraries, or slow down on merging breaking changes for a bit?

if out_col.ordered:
out_col = column.build_categorical_column(
def as_ordered(self, ordered: bool):
if self.dtype.ordered != ordered:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather flip the if/else and structure this as an early exit.

If no work is needed (self.dtype.ordered == ordered), return self immediately.

Otherwise return the longer result of build_categorical_column.

@@ -846,3 +846,8 @@ def test_empty_series_category_cast(ordered):

assert_eq(expected, actual)
assert_eq(expected.dtype.ordered, actual.dtype.ordered)


def test_categoricaldtype_ordered_not_settable():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def test_categoricaldtype_ordered_not_settable():
def test_categorical_dtype_ordered_not_settable():

@mroeschke
Copy link
Contributor Author

What is your merge plan for this? Should we test with other RAPIDS libraries, or slow down on merging breaking changes for a bit?

I think this change can wait until after GTC. Once cudf-pandas testing with the pandas test suite is back up, I am also curious to see if this helps with the pass rate as the goal here is to align with how pandas.CategoricalIndex.__init__ and CategoricalDtype behaves.

@mroeschke mroeschke marked this pull request as draft March 4, 2024 21:26
@mroeschke mroeschke changed the base branch from branch-24.04 to branch-24.06 March 18, 2024 22:11
@mroeschke
Copy link
Contributor Author

Closing in favor of #15475

@mroeschke mroeschke closed this Apr 5, 2024
@mroeschke mroeschke deleted the ref/ci/init branch April 5, 2024 21:38
rapids-bot bot pushed a commit that referenced this pull request Apr 9, 2024
…mn and CategoricalDtype (#15475)

A rehash of #14979

The `CategoricalDtype.ordered` behavior matches `pandas.CategoricalDtype.ordered` behavior.

Also combines `as_ordered` and `as_unordred` into 1 method, and avoids to `as_index` casts that are already performed elsewhere

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

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

URL: #15475
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Breaking change improvement Improvement / enhancement to an existing function Python Affects Python cuDF API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants