@@ -128,9 +128,6 @@ def test_loc_with_slices(self):
128128 with pytest .raises (NotImplementedError , match = msg ):
129129 s [Interval (3 , 4 , closed = "left" ) :]
130130
131- # TODO with non-existing intervals ?
132- # s.loc[Interval(-1, 0):Interval(2, 3)]
133-
134131 # slice of scalar
135132
136133 expected = s .iloc [:3 ]
@@ -143,9 +140,32 @@ def test_loc_with_slices(self):
143140 tm .assert_series_equal (expected , s [:2.5 ])
144141 tm .assert_series_equal (expected , s [0.1 :2.5 ])
145142
146- # slice of scalar with step != 1
147- with pytest .raises (ValueError ):
148- s [0 :4 :2 ]
143+ def test_slice_step_ne1 (self ):
144+ # GH#31658 slice of scalar with step != 1
145+ s = self .s
146+ expected = s .iloc [0 :4 :2 ]
147+
148+ result = s [0 :4 :2 ]
149+ tm .assert_series_equal (result , expected )
150+
151+ result2 = s [0 :4 ][::2 ]
152+ tm .assert_series_equal (result2 , expected )
153+
154+ def test_slice_float_start_stop (self ):
155+ # GH#31658 slicing with integers is positional, with floats is not
156+ # supported
157+ ser = Series (np .arange (5 ), IntervalIndex .from_breaks (np .arange (6 )))
158+
159+ msg = "label-based slicing with step!=1 is not supported for IntervalIndex"
160+ with pytest .raises (ValueError , match = msg ):
161+ ser [1.5 :9.5 :2 ]
162+
163+ def test_slice_interval_step (self ):
164+ # GH#31658 allows for integer step!=1, not Interval step
165+ s = self .s
166+ msg = "label-based slicing with step!=1 is not supported for IntervalIndex"
167+ with pytest .raises (ValueError , match = msg ):
168+ s [0 : 4 : Interval (0 , 1 )]
149169
150170 def test_loc_with_overlap (self ):
151171
0 commit comments