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

BUG: CategoricalIndex.where nulling out non-categories #37977

Merged
merged 3 commits into from
Nov 22, 2020

Conversation

jbrockmendel
Copy link
Member

@jbrockmendel jbrockmendel commented Nov 20, 2020

  • closes #xxxx
  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

ATM CategoricalIndex.where has some idiosyncratic behavior:

ci = CategoricalIndex(["a", "b", "c", "d"])
mask = np.array([True, False, True, False])

>>> ci.where(mask, 2)
CategoricalIndex(['a', nan, 'c', nan], categories=['a', 'b', 'c', 'd'], ordered=False, dtype='category')

This makes that call raise instead.

Index.where is only used in one place in reshape.merge. Might be worth deprecating+privatizing.

ci = CategoricalIndex(["a", "b", "c", "d"])
mask = np.array([True, False, True, False])

msg = "Cannot setitem on a Categorical with a new category"
Copy link
Contributor

Choose a reason for hiding this comment

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

this is an odd message for this operation.

Copy link
Member Author

Choose a reason for hiding this comment

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

yah thats a side-effect of de-duplicating all the validators. the datetimelike one is nicer, so im planning on doing a pass to make the categorical one behave more like the datetimelike one. that'll be a big diff since it will involve changing a lot of tests, so planning to do that in a dedicated PR

@jreback jreback added Bug Categorical Categorical Data Type labels Nov 21, 2020
@jreback
Copy link
Contributor

jreback commented Nov 21, 2020

also pls add a whatsnew note

@jbrockmendel
Copy link
Member Author

whatsnew added + green

@jreback jreback merged commit 1e21130 into pandas-dev:master Nov 22, 2020
@jreback jreback added this to the 1.2 milestone Nov 22, 2020
@jbrockmendel jbrockmendel deleted the enh-where branch November 22, 2020 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Categorical Categorical Data Type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants