Skip to content

Inconsistent Series subsetting behaviour #656

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

Closed
gerigk opened this issue Jan 20, 2012 · 1 comment
Closed

Inconsistent Series subsetting behaviour #656

gerigk opened this issue Jan 20, 2012 · 1 comment
Labels
Milestone

Comments

@gerigk
Copy link

gerigk commented Jan 20, 2012

Series in 0.7 RC1 have some weird behaviour when selecting by index.

y
a 0
0 1
1 2
Name: a
y[0]
1 # expected
y[[0,1]]
a 0 # wrong?
0 1
Name: a
y[[1,2]]
0 1
1 2
Name: a
y.ix[[0,1]] # this also doesnt work
a 0
0 1
Name: a

@wesm
Copy link
Member

wesm commented Jan 21, 2012

This actually is the behavior I would expect and you've identified a pathological ambiguous case where it's very hard for the code to know what's the right thing to do. ix uses location-based indexing whenever a sequence of integers is passed as long as the index is not integers. But in this case of course:


In [1]: s = Series([0, 1, 2], index=['a', 0, 1])

In [2]: s
Out[2]: 
a    0
0    1
1    2

In [3]: s.index.inferred_type
Out[3]: 'mixed'

You can force exact label-indexing using the reindex function. That is actually the best way to guarantee exact label-based indexing:

In [4]: s.reindex([0, 1])
Out[4]: 
0    1
1    2

@wesm wesm closed this as completed Jan 23, 2012
wesm added a commit that referenced this issue Jan 23, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants