Skip to content

Commit

Permalink
Merge pull request #5896 from ahlmss/AHLRAP-3152
Browse files Browse the repository at this point in the history
Fix bug where use of .ix[tuple(...)]=x fails to correctly check out of b...
  • Loading branch information
jreback committed Jan 9, 2014
2 parents 045e93a + cbc1465 commit 06d9d06
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Bug Fixes
- Regresssion in handling of empty Series as indexers to Series (:issue:`5877`)
- Bug in internal caching, related to (:issue:`5727`)
- Testing bug in reading json/msgpack from a non-filepath on windows under py3 (:issue:`5874`)
- Bug when assigning to .ix[tuple(...)] (:issue:`5896`)

pandas 0.13.0
-------------
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,8 @@ def _convert_to_indexer(self, obj, axis=0, is_setter=False):
return {'key': obj}

# a positional
if obj >= len(self.obj) and not isinstance(labels, MultiIndex):
if (obj >= self.obj.shape[axis] and
not isinstance(labels, MultiIndex)):
raise ValueError("cannot set by positional indexing with "
"enlargement")

Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2352,6 +2352,14 @@ def check_slicing_positional(index):
#self.assertRaises(TypeError, lambda : s.iloc[2.0:5.0])
#self.assertRaises(TypeError, lambda : s.iloc[2:5.0])

def test_set_ix_out_of_bounds_axis_0(self):
df = pd.DataFrame(randn(2, 5), index=["row%s" % i for i in range(2)], columns=["col%s" % i for i in range(5)])
self.assertRaises(ValueError, df.ix.__setitem__, (2, 0), 100)

def test_set_ix_out_of_bounds_axis_1(self):
df = pd.DataFrame(randn(5, 2), index=["row%s" % i for i in range(5)], columns=["col%s" % i for i in range(2)])
self.assertRaises(ValueError, df.ix.__setitem__, (0 , 2), 100)


if __name__ == '__main__':
import nose
Expand Down

0 comments on commit 06d9d06

Please sign in to comment.