Skip to content

xs on MultiIndex Does not Work For Series #6258

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
cancan101 opened this issue Feb 4, 2014 · 7 comments · Fixed by #6259
Closed

xs on MultiIndex Does not Work For Series #6258

cancan101 opened this issue Feb 4, 2014 · 7 comments · Fixed by #6259
Assignees
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@cancan101
Copy link
Contributor

This works:

In [141]:

dates = pd.to_datetime(['2013-09-03', '2013-09-04', '2013-09-05'])
pd.concat({'A':pd.Series([1,3,4], index=dates), 'B':pd.Series([1,3,4], index=dates)}).to_frame().xs(key='2013-09-03', level=1)

   0
A  1
B  1

[2 rows x 1 columns]

but this does not:

In [142]:

dates = pd.to_datetime(['2013-09-03', '2013-09-04', '2013-09-05'])

pd.concat({'A':pd.Series([1,3,4], index=dates), 'B':pd.Series([1,3,4], index=dates)}).xs(key='2013-09-03', level=1)

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-142-06aba7d44961> in <module>()
      1 dates = pd.to_datetime(['2013-09-03', '2013-09-04', '2013-09-05'])
----> 2 pd.concat({'A':pd.Series([1,3,4], index=dates), 'B':pd.Series([1,3,4], index=dates)}).xs(key='2013-09-03', level=1)

/usr/lib64/python2.7/site-packages/pandas/core/series.py 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

/usr/lib64/python2.7/site-packages/pandas/core/series.py in __getitem__(self, key)
    482     def __getitem__(self, key):
    483         try:
--> 484             result = self.index.get_value(self, key)
    485             if isinstance(result, np.ndarray):
    486                 return self._constructor(result,index=[key]*len(result)).__finalize__(self)

/usr/lib64/python2.7/site-packages/pandas/core/index.py 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: '2013-09-03'
@jreback
Copy link
Contributor

jreback commented Feb 4, 2014

hmm...should work...odd...marking as a bug

@jreback jreback self-assigned this Feb 4, 2014
@cancan101
Copy link
Contributor Author

I am running this on v0.13, so it might be fixed in master.

@jreback
Copy link
Contributor

jreback commented Feb 4, 2014

this is still present

of course when reporting pls give a try on master anyhow

@TomAugspurger
Copy link
Contributor

Probably related: #5684

I think I took a shot at fixing it, but scared off by the indexing code :)

@jreback
Copy link
Contributor

jreback commented Feb 4, 2014

@TomAugspurger

#6259 should fix this issue; can you check if fixes the related; if so you want to add another commit with tests for that one

xs was pretty broken - too many special cases ; not a whole lot of tests though

@TomAugspurger
Copy link
Contributor

@jreback that seems to have fixed it. Thanks!

@jreback
Copy link
Contributor

jreback commented Feb 4, 2014

gr8
do you want to add those tests on?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants