Skip to content

BUG: Add unordered option to pandas.cut (#33141) #33480

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

Merged
merged 12 commits into from
May 1, 2020

Conversation

mabelvj
Copy link
Contributor

@mabelvj mabelvj commented Apr 11, 2020

Added tests and error message when there are no labels and ordered=False.

Issue: Pandas cut raises error if labels are non-unique (Closes #33141)

@mabelvj mabelvj changed the title BUG: Add unordered option to pandas.cut. BUG: Add unordered option to pandas.cut (#33141) Apr 11, 2020
@mabelvj
Copy link
Contributor Author

mabelvj commented Apr 11, 2020

  • Updated the documentation in pandas.cut.
  • Added an example.
  • Run the documentation validation script.
  • Also added a new line in bugs -> reshaping. Should a new line about the new functionality be added in the Enhancements section?

Copy link
Member

@jschendel jschendel left a comment

Choose a reason for hiding this comment

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

Thanks! A few comments.

@jschendel jschendel added this to the 1.1 milestone Apr 13, 2020
Copy link
Member

@jschendel jschendel left a comment

Choose a reason for hiding this comment

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

lgtm, I think merging master will fix the CI failure

@jschendel
Copy link
Member

cc @pandas-dev/pandas-core

@mabelvj mabelvj requested a review from jreback April 28, 2020 16:20
@mabelvj
Copy link
Contributor Author

mabelvj commented Apr 30, 2020

Updated:
labels = Categorical(
labels,
categories=labels if len(set(labels)) == len(labels) else None,
ordered=ordered,
)

@mabelvj
Copy link
Contributor Author

mabelvj commented Apr 30, 2020

Updated:

            labels = Categorical(
                labels,
                categories=labels if len(set(labels)) == len(labels) else None,
                ordered=ordered,
            )

instead of:

            labels = Categorical(
                labels,
                categories=labels if ordered else None,
                ordered=ordered,
            )

since we need to also handle the case of unordered labels. We just need to avoid passing duplicates labels to categories and also raise an error when we are using ordered=True and there are duplicate labels.

@jreback jreback merged commit d04b965 into pandas-dev:master May 1, 2020
@jreback
Copy link
Contributor

jreback commented May 1, 2020

thanks @mabelvj very nice!

rhshadrach pushed a commit to rhshadrach/pandas that referenced this pull request May 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pandas cut method gives an error if labels are non-unique
4 participants