Skip to content

minor inconsistency in Categorical.remove_categories error message #28677

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 38 commits into from
Oct 22, 2019
Merged

minor inconsistency in Categorical.remove_categories error message #28677

merged 38 commits into from
Oct 22, 2019

Conversation

punndcoder28
Copy link
Contributor

@punndcoder28 punndcoder28 commented Sep 30, 2019

This pull request fixes minor inconsistency in Categorical.remove_categories error message

Changed the error message to show invalid removals as a set. Added tests for removal of null from the categories. Parameterized pytest.

@pep8speaks
Copy link

pep8speaks commented Sep 30, 2019

Hello @punndcoder28! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2019-10-09 17:53:34 UTC

@jbrockmendel
Copy link
Member

Nitpick: in the future please give the PR an informative title. Most reviewers won't know off the top of their heads what 28677 is about.

@punndcoder28
Copy link
Contributor Author

punndcoder28 commented Oct 1, 2019

Yes my bad @jbrockmendel. I realized it after opening the PR sorry.

@jreback jreback changed the title Fix #28669 minor inconsistency in Categorical.remove_categories error message Oct 1, 2019
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

can you add or update the tests on remove_categories to account for this change (since nothing broke we likely are not testing it enough)

@jreback jreback added Error Reporting Incorrect or improved errors from pandas Categorical Categorical Data Type labels Oct 1, 2019
@punndcoder28
Copy link
Contributor Author

I had tests as it were suggested by @simonjayhawkins. But there were errors and I didn't know how to handle that. If I could get some guidance I will surely add those and commit the changes.

@punndcoder28
Copy link
Contributor Author

If you could tell me what tests I should create I'll create those and commit @jreback.

@simonjayhawkins
Copy link
Member

@punndcoder28 suitable tests would be similar to those in pandas/tests/arrays/categorical/test_api.py in 8298620

Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

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

@punndcoder28 Thanks for the PR. can you add a whatsnew entry as well.

@punndcoder28
Copy link
Contributor Author

assert [NaN, b, c, NaN]\nCategories (2, object): [b < c] is None. This shouldn't cause an error right. As [b < c] is None states the statement assert res is None should evaluate to True and should not raise an AssertionError. Am I understanding this the wrong way?

Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

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

@punndcoder28 generally looks good. a couple of small changes. also need to merge master to resolve merge conflict. ping on green.

@punndcoder28
Copy link
Contributor Author

punndcoder28 commented Oct 8, 2019

@punndcoder28 generally looks good. a couple of small changes. also need to merge master to resolve merge conflict. ping on green.

How do I resolve a conflict? I tried doing it manually but didn't work.

@simonjayhawkins
Copy link
Member

How do I resolve a conflict? I tried doing it manually but didn't work.

see https://dev.pandas.io/docs/development/contributing.html#updating-your-pull-request

git fetch upstream
git merge upstream/master

@jreback jreback added this to the 1.0 milestone Oct 8, 2019
@punndcoder28
Copy link
Contributor Author

I did what was mentioned here

ci is failing, see https://dev.pandas.io/docs/development/contributing.html#python-pep8-black

But still the tests are failing.

@jbrockmendel
Copy link
Member

You need to run isort pandas/tests/arrays/categorical/test_api.py

Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

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

@WillAyd
Copy link
Member

WillAyd commented Oct 22, 2019

Hmm is this actually changing anything on master? I ran one of the test cases but already see the intended result?

>>> pd.Categorical(["a", "b", "a"]).remove_categories(["c", "c"])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/williamayd/clones/pandas/pandas/core/arrays/categorical.py", line 1132, in remove_categories
    raise ValueError(msg.format(not_included=not_included))
ValueError: removals must all be in old categories: {'c'}

@simonjayhawkins
Copy link
Member

it's changeing the output of cat = cat.remove_categories(["c", np.nan])

from ValueError: removals must all be in old categories: ['c']

to ValueError: removals must all be in old categories: {'c'}

for all other cases the message remain unchanged and tests are added for these. i.e.

cat = cat.remove_categories(["c"])
cat = cat.remove_categories("c")
cat = cat.remove_categories(["c", "c"])

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

Ah OK thanks for clarifying @simonjayhawkins

@WillAyd WillAyd merged commit 59d1a69 into pandas-dev:master Oct 22, 2019
@WillAyd
Copy link
Member

WillAyd commented Oct 22, 2019

Thanks @punndcoder28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Categorical Categorical Data Type Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

minor inconsistency in Categorical.remove_categories error message
7 participants