From 68581d2a1252bd534aa2b7c3084e799a38af85b6 Mon Sep 17 00:00:00 2001 From: da415 Date: Mon, 25 Mar 2013 14:24:54 +0000 Subject: [PATCH] Index out of bounds error raised for negative indices. Accessing out of bounds negative timeseries indices silently return nonsense values. --- pandas/src/util.pxd | 4 ++-- pandas/tests/test_series.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pandas/src/util.pxd b/pandas/src/util.pxd index 7a30f018e623e..7c04b733d8ff0 100644 --- a/pandas/src/util.pxd +++ b/pandas/src/util.pxd @@ -34,9 +34,9 @@ cdef inline object get_value_at(ndarray arr, object loc): i = loc sz = cnp.PyArray_SIZE(arr) - if i < 0 and sz > 0: + if i < 0 and -sz < i and sz > 0: i += sz - elif i >= sz or sz == 0: + elif i >= sz or i < -sz: raise IndexError('index out of bounds') return get_value_1d(arr, i) diff --git a/pandas/tests/test_series.py b/pandas/tests/test_series.py index cc69649f24cdf..6ff0638700fa8 100644 --- a/pandas/tests/test_series.py +++ b/pandas/tests/test_series.py @@ -764,6 +764,9 @@ def test_getitem_out_of_bounds(self): s = Series([]) self.assertRaises(IndexError, s.__getitem__, -1) + # GH # + self.assertRaises(IndexError, s.__getitem__, - len(self.ts) - 1) + def test_getitem_setitem_integers(self): # caused bug without test s = Series([1, 2, 3], ['a', 'b', 'c'])