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

df.xs() level argument behavior changed. #1796

Closed
lodagro opened this issue Aug 21, 2012 · 1 comment
Closed

df.xs() level argument behavior changed. #1796

lodagro opened this issue Aug 21, 2012 · 1 comment
Assignees
Labels
Milestone

Comments

@lodagro
Copy link
Contributor

lodagro commented Aug 21, 2012

When using xs in combination with a MultiIndex, before it was not needed to specify the level argument if key started from level 0 and referred to consecutive levels (see also the examples described in #1684), now this no longer works and level needs to be defined in case key is a list.

In [74]: df
Out[74]: 
                       A         B         C         D
lvl0 lvl1 lvl2                                        
foo  one  -1   -0.945315  0.355323 -1.292034 -0.241153
           1   -0.798705 -0.155502  0.269164  2.659962
     two  -1    1.059727 -1.624291 -0.199047 -1.080560
           1    0.937473 -0.726302  0.848377  0.450377
bar  one  -1    0.473692  0.135078  0.066102 -0.922182
           1   -0.059887  0.306716  1.933680 -1.314217
     two  -1   -0.182526 -0.074111 -1.305636 -0.404485
           1   -0.913486  1.758551  0.575856  0.560052

In [75]: df.xs(['foo', 'one'])
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-75-deeb03cdd75e> in <module>()
----> 1 df.xs(['foo', 'one'])
...
TypeError: 

In [76]: df.xs(['foo', 'one'], level=[0, 1])
Out[76]: 
             A         B         C         D
lvl2                                        
-1   -0.945315  0.355323 -1.292034 -0.241153
 1   -0.798705 -0.155502  0.269164  2.659962
@wesm
Copy link
Member

wesm commented Sep 18, 2012

Had to insert a little kludge to get this one to work-- tuples were working as a key (('foo', 'one')) but not lists

yarikoptic added a commit to neurodebian/pandas that referenced this issue Sep 27, 2012
Version 0.9.0 Release Candidate 1

* tag 'v0.9.0rc1': (58 commits)
  RLS: Version 0.9.0 Release Candidate 1
  BLD: add lib depends pandas-dev#1945
  BUG: missing case for assigning DataFrame via ix
  BUG: python 3.1 timedelta compat issue
  BUG: python 3 tzoffset is not hashable
  TST: adds dateutil to travis-ci install commands
  BUG: let selecting multiple columns in DataFrame.__getitem__ work when there are duplicates. close pandas-dev#1943
  BUG: DatetimeConverter does not handle datetime64 arrays properly
  BUG: reindex with axis=1 when setting Series to scalar location, close pandas-dev#1942
  BUG: fix formatting of Timestamps in to_html/IPython notebook. refactor to_html code. close pandas-dev#1940
  ENH: allow single str input to na_values pandas-dev#1944
  TST: when xlrd is not installed skip tests needing it, close pandas-dev#1941
  BUG: DatetimeIndex localizes twice if input is localized DatetimeIndex pandas-dev#1838
  BUG: align input on setting via ix pandas-dev#1630
  cython methods for group bins pandas-dev#1809
  BUG: allow non-numeric columns in groupby first/last pandas-dev#1809
  TST: skip unicode filename test if system requires encoding to ascii
  BUG: more fixedoffset occurrences pandas-dev#1928
  BUG: no zone in tzinfo pandas-dev#1838
  BUG: handle lists too in DataFrame.xs when partially selecting data from DataFrame. close pandas-dev#1796
  ...
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