-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Series.xs() inconsistent with DataFrame.xs() with MultiIndex #5684
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
Comments
This is correct (though prob not what you want)
You should set names like this, FYI
(9) is correct
ix like behavior
correct
Your last example |
For the last one, I missed a copy paste: In [65]: df
Out[65]:
L1 L2
a one 1.041627
two -0.553980
b one -1.491640
two -0.026511
dtype: float64
In [66]: df.xs('one', level='L2')
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-66-52601adf5184> in <module>()
----> 1 df.xs('one', level='L2')
/Users/tom/Envs/pandas-dev/lib/python2.7/site-packages/pandas-0.13.0rc1_27_g4d5ca5c-py2.7-macosx-10.8-x86_64.egg/pandas/core/series.pyc in _xs(self, key, axis, level, copy)
437
438 def _xs(self, key, axis=0, level=None, copy=True):
--> 439 return self.__getitem__(key)
440
441 xs = _xs
/Users/tom/Envs/pandas-dev/lib/python2.7/site-packages/pandas-0.13.0rc1_27_g4d5ca5c-py2.7-macosx-10.8-x86_64.egg/pandas/core/series.pyc in __getitem__(self, key)
482 def __getitem__(self, key):
483 try:
--> 484 return self.index.get_value(self, key)
485 except InvalidIndexError:
486 pass
/Users/tom/Envs/pandas-dev/lib/python2.7/site-packages/pandas-0.13.0rc1_27_g4d5ca5c-py2.7-macosx-10.8-x86_64.egg/pandas/core/index.pyc in get_value(self, series, key)
2294 raise InvalidIndexError(key)
2295 else:
-> 2296 raise e1
2297 except Exception: # pragma: no cover
2298 raise e1
KeyError: 'one' And I guess the most surprising thing here is the inconsistency across DataFrames and Series: In [69]: df = pd.DataFrame(df)
In [70]: df.xs('one', level='L2')
Out[70]:
0
L1
a 1.041627
b -1.491640
[2 rows x 1 columns] Sorry this is such a mess of an issue. I think the last one is the only real bug then? I'll edit my post/title to reflect that, if it's actually a bug. |
yep...last one is a bug then. |
@TomAugspurger maybe just edit the Top section to reflect the bug |
Edited to clarify the bug
Series.xs
slice fails with string index labels and MultiIndex:The same slice works on a DataFrame.
Previous post below:
Works for DataFrames:
Series.xs
also seems to fail on string index labels?So I guess this is about 3 errors on
Series.xs
(possibly related?):level>1
when the label is a string.EDIT: Oh, and I know that
.loc
/.ix
will work for these. I was just surprised by the results.The text was updated successfully, but these errors were encountered: