Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ pandas 0.11.0
- Fix NameError issue on RESO_US (GH2787_)
- Allow selection in an *unordered* timeseries to work similary
to an *ordered* timeseries (GH2437_).
- Fix implemented ``.xs`` when called with ``axes=1`` and a level parameter (GH2903_)

.. _GH2758: https://github.com/pydata/pandas/issues/2758
.. _GH2758: https://github.com/pydata/pandas/issues/2758
.. _GH2809: https://github.com/pydata/pandas/issues/2809
.. _GH2810: https://github.com/pydata/pandas/issues/2810
.. _GH2837: https://github.com/pydata/pandas/issues/2837
Expand Down Expand Up @@ -257,6 +258,7 @@ pandas 0.11.0
.. _GH2850: https://github.com/pydata/pandas/issues/2850
.. _GH2898: https://github.com/pydata/pandas/issues/2898
.. _GH2892: https://github.com/pydata/pandas/issues/2892
.. _GH2903: https://github.com/pydata/pandas/issues/2903
.. _GH2909: https://github.com/pydata/pandas/issues/2909
.. _GH2922: https://github.com/pydata/pandas/issues/2922
.. _GH2929: https://github.com/pydata/pandas/issues/2929
Expand Down
6 changes: 5 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2211,7 +2211,11 @@ def xs(self, key, axis=0, level=None, copy=True):
if labels.levels[lev_num].inferred_type == 'integer':
indexer = self.index[loc]

result = self.ix[indexer]
# select on the correct axis
if axis == 1:
result = self.ix[:, indexer]
else:
result = self.ix[indexer]
setattr(result, result._get_axis_name(axis), new_ax)
return result

Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,16 @@ def test_ix_general(self):
df.sortlevel(inplace=True)
df.ix[(4.0,2012)]

def test_xs_multiindex(self):

# GH2903
columns = MultiIndex.from_tuples([('a', 'foo'), ('a', 'bar'), ('b', 'hello'), ('b', 'world')], names=['lvl0', 'lvl1'])
df = DataFrame(np.random.randn(4, 4), columns=columns)
df.sortlevel(axis=1,inplace=True)
result = df.xs('a', level='lvl0', axis=1)
expected = df.iloc[:,0:2].loc[:,'a']
assert_frame_equal(result,expected)

if __name__ == '__main__':
import nose
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
Expand Down