Skip to content

Commit

Permalink
BUG: fix scalar setting via ix with MultiIndex, GH #551
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Dec 29, 2011
1 parent 5c447dd commit 716ebdc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ pandas 0.6.2
- Handle all NA case in Series.corr, was raising exception (GH #548)
- Aggregating by multiple levels with ``level`` argument to DataFrame, Series
stat method, was broken (GH #545)
- Fix Cython buf when converter passed to read_csv produced a numeric array
(buffer dtype mismatch when passed to Cython type inference function) (GH
#546)
- Fix exception when setting scalar value using .ix on a DataFrame with a
MultiIndex (GH #551)

Thanks
------
Expand Down
6 changes: 6 additions & 0 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ def _convert_to_indexer(self, obj, axis=0):
- No, prefer label-based indexing
"""
index = self.obj._get_axis(axis)

try:
return index.get_loc(obj)
except (KeyError, TypeError):
pass

is_int_index = _is_integer_index(index)
if isinstance(obj, slice):
if _is_label_slice(index, obj):
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/test_multilevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,16 @@ def test_setitem_change_dtype(self):
reindexed = dft.reindex(columns=[('foo', 'two')])
assert_series_equal(reindexed['foo', 'two'], s > s.median())

def test_frame_setitem_ix(self):
self.frame.ix[('bar', 'two'), 'B'] = 5
self.assertEquals(self.frame.ix[('bar', 'two'), 'B'], 5)

# with integer labels
df = self.frame.copy()
df.columns = range(3)
df.ix[('bar', 'two'), 1] = 7
self.assertEquals(df.ix[('bar', 'two'), 1], 7)

def test_fancy_slice_partial(self):
result = self.frame.ix['bar':'baz']
expected = self.frame[3:7]
Expand Down

0 comments on commit 716ebdc

Please sign in to comment.