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.get_loc returns array even if it is unique #12531

Closed
wants to merge 1 commit into from

Conversation

sinhrks
Copy link
Member

@sinhrks sinhrks commented Mar 5, 2016

Made CategoricalIndex.get_loc to return the same result as normal Index.

data2 = pd.DataFrame([[1,2,3],[3,4,5]], index=pd.Categorical(['one', 'two']))

# in current master, it returns DataFrame with 1 row 
data2.ix['one']
#      0  1  2
# one  1  2  3

# after this PR, it returns Series
data2.ix['one']
#0    1
#1    2
#2    3
# Name: one, dtype: int64

@sinhrks sinhrks added Indexing Related to indexing on series/frames, not to indexes themselves Categorical Categorical Data Type labels Mar 5, 2016
@sinhrks sinhrks added this to the 0.18.1 milestone Mar 5, 2016
@jreback
Copy link
Contributor

jreback commented Mar 12, 2016

@sinhrks this looks good. but is this the correct reference issue: #11588 ?

@sinhrks
Copy link
Member Author

sinhrks commented Mar 14, 2016

Ah, related to #11558, but can't close only by this PR. Fixed the doc and comment.

@@ -1925,6 +1925,50 @@ def test_getitem_ix_float_duplicates(self):
expect = df.iloc[[1, -1], 0]
assert_series_equal(df.loc[0.2, 'a'], expect)

def test_getitem_ix_categorical_index(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

I would move these tests to tests/indexing/tests_categoricaly.py (I just reorged this recently)

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, moved.

@jreback
Copy link
Contributor

jreback commented Mar 15, 2016

@sinhrks thanks! nice PR as usual

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

None yet

2 participants