-
- Notifications
You must be signed in to change notification settings - Fork 19.4k
BUG: loc returning wrong elements for non-monotonic DatetimeIndex #38010
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 all commits
cf20270 e8ac2d2 b7b0047 e8aed44 3db4719 f93c608 24386fb 7931439 05dcac2 b61dab9 8ee5b61 406b7dc db49d3f f990e53 54f000b 65f2f88 9759787 d194e48 a15cea3 2b6beb3 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 |
|---|---|---|
| | @@ -15,6 +15,7 @@ | |
| Categorical, | ||
| CategoricalIndex, | ||
| DataFrame, | ||
| DatetimeIndex, | ||
| Index, | ||
| MultiIndex, | ||
| Series, | ||
| | @@ -1556,6 +1557,42 @@ def test_loc_getitem_str_timedeltaindex(self): | |
| sliced = df.loc["0 days"] | ||
| tm.assert_series_equal(sliced, expected) | ||
| | ||
| @pytest.mark.parametrize("indexer_end", [None, "2020-01-02 23:59:59.999999999"]) | ||
| Member 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. do we need/want tzaware case? Member Author 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 don't think we need them, since we are indexing with strings? Member 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 meant for the index to be tzaware Member Author 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. Ah, thx. Is this the right fixture? | ||
| def test_loc_getitem_partial_slice_non_monotonicity( | ||
| self, tz_aware_fixture, indexer_end, frame_or_series | ||
| ): | ||
| # GH#33146 | ||
| obj = frame_or_series( | ||
| [1] * 5, | ||
| index=DatetimeIndex( | ||
| [ | ||
| Timestamp("2019-12-30"), | ||
| Timestamp("2020-01-01"), | ||
| Timestamp("2019-12-25"), | ||
| Timestamp("2020-01-02 23:59:59.999999999"), | ||
| Timestamp("2019-12-19"), | ||
| ], | ||
| tz=tz_aware_fixture, | ||
| ), | ||
| ) | ||
| expected = frame_or_series( | ||
| [1] * 2, | ||
| index=DatetimeIndex( | ||
| [ | ||
| Timestamp("2020-01-01"), | ||
| Timestamp("2020-01-02 23:59:59.999999999"), | ||
| ], | ||
| tz=tz_aware_fixture, | ||
| ), | ||
| ) | ||
| indexer = slice("2020-01-01", indexer_end) | ||
| | ||
| result = obj[indexer] | ||
| tm.assert_equal(result, expected) | ||
| | ||
| result = obj.loc[indexer] | ||
| tm.assert_equal(result, expected) | ||
| | ||
| | ||
| class TestLabelSlicing: | ||
| def test_loc_getitem_label_slice_across_dst(self): | ||
| | @@ -1652,7 +1689,7 @@ def test_loc_getitem_slice_columns_mixed_dtype(self): | |
| # GH: 20975 | ||
| df = DataFrame({"test": 1, 1: 2, 2: 3}, index=[0]) | ||
| expected = DataFrame( | ||
| data=[[2, 3]], index=[0], columns=pd.Index([1, 2], dtype=object) | ||
| data=[[2, 3]], index=[0], columns=Index([1, 2], dtype=object) | ||
| ) | ||
| tm.assert_frame_equal(df.loc[:, 1:], expected) | ||
| | ||
| | @@ -1858,7 +1895,7 @@ def test_loc_set_dataframe_multiindex(): | |
| | ||
| def test_loc_mixed_int_float(): | ||
| # GH#19456 | ||
| ser = Series(range(2), pd.Index([1, 2.0], dtype=object)) | ||
| ser = Series(range(2), Index([1, 2.0], dtype=object)) | ||
| | ||
| result = ser.loc[1] | ||
| assert result == 0 | ||
| | ||
Uh oh!
There was an error while loading. Please reload this page.