Skip to content

Commit

Permalink
BUG: address GH #185, prevent use of step in label-based slicing
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Sep 30, 2011
1 parent 775c12b commit 1371d0f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ def _convert_to_indexer(self, obj, axis=0):
if isinstance(obj, slice):
if _is_label_slice(index, obj):
i, j = index.slice_locs(obj.start, obj.stop)

if obj.step is not None:
raise Exception('Non-zero step not supported with '
'label-based slicing')
return slice(i, j)
else:
return obj
Expand Down Expand Up @@ -238,6 +242,10 @@ def _get_slice_axis(self, slice_obj, axis=0):
if _is_label_slice(labels, slice_obj):
i, j = labels.slice_locs(slice_obj.start, slice_obj.stop)
slicer = slice(i, j)

if slice_obj.step is not None:
raise Exception('Non-zero step not supported with label-based '
'slicing')
else:
slicer = slice_obj

Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ def test_getitem_fancy_2d(self):
exp.values[5:10] = 5
assert_frame_equal(f, exp)

def test_getitem_fancy_slice_integers_step(self):
df = DataFrame(np.random.randn(10, 5))
self.assertRaises(Exception, df.ix.__getitem__, slice(0, 8, 2))

def test_setitem_fancy_2d(self):
f = self.frame
ix = f.ix
Expand Down

0 comments on commit 1371d0f

Please sign in to comment.