[pandas] 01/02: Fix bug where use of .ix[tuple(...)]=x fails to correctly check out of bounds index for columns. This is a regression as it used to work in pandas 0.12.0. The code incorrectly checks the column index against the len() of the dataframe to see if it is in bounds not against the number of columns. Have added 2 tests with non-square dataframes to test that the fix works.
Andreas Tille
tille at debian.org
Wed Dec 28 15:20:16 UTC 2016
This is an automated email from the git hooks/post-receive script.
tille pushed a commit to annotated tag v0.13.0_ahl2
in repository pandas.
commit 65cf5c44321a86f8d3dea6431e2cf2f8adb0add8
Author: Andrew Burrows <aburrows at gmail.com>
Date: Thu Jan 9 17:01:41 2014 +0000
Fix bug where use of .ix[tuple(...)]=x fails to correctly check out of bounds index for columns. This is a regression as it used to work in pandas 0.12.0. The code incorrectly checks the column index against the len() of the dataframe to see if it is in bounds not against the number of columns. Have added 2 tests with non-square dataframes to test that the fix works.
---
pandas/core/indexing.py | 3 ++-
pandas/tests/test_indexing.py | 8 ++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py
index bfddd2e..0697f9d 100644
--- a/pandas/core/indexing.py
+++ b/pandas/core/indexing.py
@@ -903,7 +903,8 @@ class _NDFrameIndexer(object):
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")
diff --git a/pandas/tests/test_indexing.py b/pandas/tests/test_indexing.py
index fe3aac0..87f649d 100644
--- a/pandas/tests/test_indexing.py
+++ b/pandas/tests/test_indexing.py
@@ -2324,6 +2324,14 @@ class TestIndexing(tm.TestCase):
#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
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/pandas.git
More information about the debian-science-commits
mailing list