-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Slicing non monotonic DatetimeIndex did not raise for non-existing keys #37796
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 7 commits
edfb289
68af482
725cfb6
0154c11
c051d64
1814c53
069dcd9
f248514
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 | ||
---|---|---|---|---|
|
@@ -1564,6 +1564,19 @@ def test_loc_getitem_slice_label_td64obj(self, start, stop, expected_slice): | |||
expected = ser.iloc[expected_slice] | ||||
tm.assert_series_equal(result, expected) | ||||
|
||||
def test_loc_getitem_slice_unordered_dt_index(self, frame_or_series): | ||||
# GH#18531 | ||||
obj = frame_or_series( | ||||
[1, 2, 3], | ||||
index=[Timestamp("2017"), Timestamp("2019"), Timestamp("2018")], | ||||
) | ||||
with pytest.raises(KeyError, match=r"Timestamp\('2020-01-01 00:00:00'\)"): | ||||
obj.loc["2020":"2022"] | ||||
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. Can you also add an example where the label falls within the range of the Index? 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. This works, because of pandas/pandas/core/indexes/datetimes.py Line 799 in 72d4b78
Should we remove or deprecate? Harder fix than the previous one 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. hmm, i guess we could try to deprecate, @jorisvandenbossche you feel strongly here? |
||||
|
||||
obj.index = ["a", "c", "b"] | ||||
with pytest.raises(KeyError, match=r"d"): | ||||
obj.loc["d":"e"] | ||||
|
||||
|
||||
class TestLocBooleanMask: | ||||
def test_loc_setitem_bool_mask_timedeltaindex(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.
can you add the str index example from the OP as well. ping on green.
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.
Interestingly enough this does not raise any more. I will open an issue for this. We have to define if
slice_locs
should raise too or if we should doo this after calling the function. Is not related to the DateTime fix.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.
#37810