-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
API: allow step!=1 slice with IntervalIndex #31658
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
Changes from 28 commits
7a26837
b371805
b78c4c3
e3631d9
7949ffd
4c2e703
88a7ace
0da92c5
f833f7c
041edbc
a2eb9bb
6b97b09
abdbd76
a678ec2
2c684cc
e4cc38d
10165b4
8308eb8
2bffbda
0bdb7b5
adf0775
2744a4b
cf1a393
74a40ff
9a04d41
f6360a6
d636108
9222513
2a698c0
d18c7a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,9 +128,6 @@ def test_loc_with_slices(self): | |
with pytest.raises(NotImplementedError, match=msg): | ||
s[Interval(3, 4, closed="left") :] | ||
|
||
# TODO with non-existing intervals ? | ||
# s.loc[Interval(-1, 0):Interval(2, 3)] | ||
|
||
# slice of scalar | ||
|
||
expected = s.iloc[:3] | ||
|
@@ -143,9 +140,32 @@ def test_loc_with_slices(self): | |
tm.assert_series_equal(expected, s[:2.5]) | ||
tm.assert_series_equal(expected, s[0.1:2.5]) | ||
|
||
# slice of scalar with step != 1 | ||
with pytest.raises(ValueError): | ||
s[0:4:2] | ||
def test_slice_step_ne1(self): | ||
# GH#31658 slice of scalar with step != 1 | ||
s = self.s | ||
expected = s.iloc[0:4:2] | ||
|
||
result = s[0:4:2] | ||
tm.assert_series_equal(result, expected) | ||
|
||
result2 = s[0:4][::2] | ||
tm.assert_series_equal(result2, expected) | ||
|
||
def test_slice_float_start_stop(self): | ||
# GH#31658 slicing with integers is positional, with floats is not | ||
# supported | ||
ser = Series(np.arange(5), IntervalIndex.from_breaks(np.arange(6))) | ||
|
||
msg = "label-based slicing with step!=1 is not supported for IntervalIndex" | ||
with pytest.raises(ValueError, match=msg): | ||
ser[1.5:9.5:2] | ||
|
||
def test_slice_interval_step(self): | ||
# GH#31658 allows for integer step!=1, not Interval step | ||
s = self.s | ||
msg = "label-based slicing with step!=1 is not supported for IntervalIndex" | ||
with pytest.raises(ValueError, match=msg): | ||
s[0 : 4 : Interval(0, 1)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would test it where start and stop are also intervals. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
out of scope
sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think that is not out of scope, as that hits this path, and right now actually ensured there is a proper error message. |
||
|
||
def test_loc_with_overlap(self): | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: interpretd --> interpreted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated