Skip to content

BUG: loc-indexing with a slice on a CategoricalIndex #30225

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

Conversation

topper-123
Copy link
Contributor

#29922 didn't handle loc-indexing using a slice on non-string CategoricalIndexes. This fixes that. E.g. we had:

>>> cat_idx = pd.CategoricalIndex([1,2,3], ordered=True)
>>> df = pd.DataFrame({"A": ["foo", "bar", "baz"]}, index=cat_idx)
>>> df.loc[1:2, "A"]
TypeError: cannot do slice indexing on...

The above works now.

@topper-123 topper-123 force-pushed the indexing_categoricalindex_with_slice branch from 6d42b2a to 98fa970 Compare December 12, 2019 10:13
@jreback jreback added Bug Categorical Categorical Data Type Indexing Related to indexing on series/frames, not to indexes themselves labels Dec 12, 2019
@jreback jreback added this to the 1.0 milestone Dec 12, 2019
@jreback jreback merged commit 96bb151 into pandas-dev:master Dec 12, 2019
@jreback
Copy link
Contributor

jreback commented Dec 12, 2019

thanks @topper-123 very nice

@topper-123 topper-123 deleted the indexing_categoricalindex_with_slice branch December 12, 2019 15:04
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Categorical Categorical Data Type Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants