diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 7a41b1e2c69ba..c87682fd4f672 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -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 @@ -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 diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index 259ef2f6c8ba8..6530af8e5dfc3 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -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