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

Multi-Index Slice Selection in Series #6018

Closed
theandygross opened this issue Jan 20, 2014 · 1 comment · Fixed by #6022

Comments

@theandygross
Copy link
Contributor

commented Jan 20, 2014

Slicing in Series with MultiIndex does not seem to work on master with .ix or .loc. This is not comparable with previous versions.

In [54]:  

s = pd.Series([1,2,3])
s.index = pd.MultiIndex.from_tuples([(0,0),(1,1), (2,1)])
s[:,0]

Out[55]:  

1    2
2    3

In [56]:  

s.ix[:,1]


IndexingError                             

Traceback (most recent call last)
<ipython-input-56-3163789d3245> in <module>()
----> 1 s.ix[:,1]

/cellar/users/agross/anaconda2/lib/python2.7/site-packages/pandas-0.13.0_120_gdd89ce4-py2.7-linux-x86_64.egg/pandas/core/indexing.pyc in __getitem__(self, key)
     52                 pass
     53 
---> 54             return self._getitem_tuple(key)
     55         else:
     56             return self._getitem_axis(key, axis=0)

/cellar/users/agross/anaconda2/lib/python2.7/site-packages/pandas-0.13.0_120_gdd89ce4-py2.7-linux-x86_64.egg/pandas/core/indexing.pyc in _getitem_tuple(self, tup)
    593 
    594         # no multi-index, so validate all of the indexers
--> 595         self._has_valid_tuple(tup)
    596 
    597         # ugly hack for GH #836

/cellar/users/agross/anaconda2/lib/python2.7/site-packages/pandas-0.13.0_120_gdd89ce4-py2.7-linux-x86_64.egg/pandas/core/indexing.pyc in _has_valid_tuple(self, key)
    103         for i, k in enumerate(key):
    104             if i >= self.obj.ndim:
--> 105                 raise IndexingError('Too many indexers')
    106             if not self._has_valid_type(k, i):
    107                 raise ValueError("Location based indexing can only have [%s] "

IndexingError: Too many indexers
@jreback

This comment has been minimized.

Copy link
Contributor

commented Jan 21, 2014

Allowing multiple indexers on a Series IMHO is wrong and shouldn't be allowed; instead you should use xs
(to be fair this didn't exist in 0.12, that's why its allowed :)

so fixed this, and fixed xs on a Series which wasn't working properly

e.g.

Series.xs(1,level=1) is what you want

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.