Skip to content

BUG: GH3168 bug in integer out-of-bounds indexing in Series causing segfault #3191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ pandas 0.11.0
- PeriodIndex.tolist now boxes to Period (GH3178_)
- PeriodIndex.get_loc KeyError now reports Period instead of ordinal (GH3179_)
- df.to_records bug when handling MultiIndex (GH3189)
- Bug in integer out-of-bounds indexing in Series causing segfault (GH3168_)

.. _GH622: https://github.com/pydata/pandas/issues/622
.. _GH797: https://github.com/pydata/pandas/issues/797
Expand Down Expand Up @@ -304,9 +305,13 @@ pandas 0.11.0
.. _GH3075: https://github.com/pydata/pandas/issues/3075
.. _GH3094: https://github.com/pydata/pandas/issues/3094
.. _GH3130: https://github.com/pydata/pandas/issues/3130
<<<<<<< HEAD
.. _GH3178: https://github.com/pydata/pandas/issues/3178
.. _GH3179: https://github.com/pydata/pandas/issues/3179
.. _GH3189: https://github.com/pydata/pandas/issues/3189
=======
.. _GH3168: https://github.com/pydata/pandas/issues/3168
>>>>>>> BUG: GH3168 bug in integer out-of-bounds indexing in Series causing segfault (GH3168_)

pandas 0.10.1
=============
Expand Down
6 changes: 5 additions & 1 deletion pandas/src/util.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ cdef inline object get_value_at(ndarray arr, object loc):

if i < 0 and sz > 0:
i += sz
if i > sz or i < 0:
raise IndexError('index out of bounds')
elif i >= sz or sz == 0:
raise IndexError('index out of bounds')

Expand All @@ -53,7 +55,9 @@ cdef inline set_value_at(ndarray arr, object loc, object value):

if i < 0:
i += sz
elif i >= sz:
if i > sz or i < 0:
raise IndexError('index out of bounds')
elif i >= sz or i < 0:
raise IndexError('index out of bounds')

assign_value_1d(arr, i, value)
Expand Down
25 changes: 25 additions & 0 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3988,6 +3988,31 @@ def test_int_indexing(self):
self.assertRaises(KeyError, s.__getitem__, 'c')
self.assertRaises(KeyError, s.__setitem__, 'c', 0)

def test_neg_indices_indexing(self):

from pandas.util.testing import makeCustomDataframe as mkdf
s = mkdf(10,5,r_idx_type='dt').C_l0_g0

# GH 3168 getting
self.assert_(s[0] == 'R0C0')
self.assert_(s[-1] == 'R9C0')

self.assertRaises(KeyError, s.__getitem__, tuple([-11]))

# GH 3168 setting
s[0] = 'foo'
self.assert_(s[0] == 'foo')
s[-1] = 'foo'
self.assert_(s[-1] == 'foo')

self.assertRaises(KeyError, s.__setitem__, tuple([-11]), 'foo')

# 0-len
s = Series([])
for l in [0,1,-1]:
self.assertRaises(KeyError, s.__getitem__, tuple([l]))
self.assertRaises(KeyError, s.__setitem__, tuple([l]), 'foo')

def test_datetime_indexing(self):
from pandas import date_range

Expand Down
2 changes: 2 additions & 0 deletions pandas/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ cpdef object get_value_box(ndarray arr, object loc):

if i < 0 and sz > 0:
i += sz
if i > sz or i < 0:
raise IndexError('index out of bounds')
elif i >= sz or sz == 0:
raise IndexError('index out of bounds')

Expand Down