-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
REGR: fix bug in DatetimeIndex slicing with irregular or unsorted indices #37023
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 11 commits
f1d4a10
cd1a136
fe478c4
15a9185
6caba47
5703994
4a7ff03
25b229c
9bb10fe
9d82f83
968fdf4
89b0248
3710514
237b085
43a2a26
632855b
e79cdac
e5f3615
4261f02
583003e
e246520
9cf919e
7f693dc
02ae223
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 |
---|---|---|
|
@@ -3739,7 +3739,6 @@ def _slice(self: FrameOrSeries, slobj: slice, axis=0) -> FrameOrSeries: | |
|
||
Slicing with this method is *always* positional. | ||
""" | ||
assert isinstance(slobj, slice), type(slobj) | ||
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 is not the patch; something is going down the wrong path and ending up here. this routine is only for slices. 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. Ok, I will look into that. I just wanted to note that in version 1.0.9 it went down just the same path except that the exception wasn't there yet. In this sense we are not talking about a regression but about fixing a bug which seems to have been there since a while ago. 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. @CloseChoice can you check if the suggestion from here #35509 (comment) passes the tests you added? |
||
axis = self._get_block_manager_axis(axis) | ||
result = self._constructor(self._mgr.get_slice(slobj, axis=axis)) | ||
result = result.__finalize__(self) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -681,3 +681,22 @@ def test_index_name_empty(self): | |
{"series": [1.23] * 4}, index=pd.RangeIndex(4, name="series_index") | ||
) | ||
tm.assert_frame_equal(df, expected) | ||
|
||
def test_slice_irregular_datetime_index_with_nan(self): | ||
# GH36953 | ||
index = pd.to_datetime(["2012-01-01", "2012-01-02", "2012-01-03", None]) | ||
df = pd.DataFrame(range(len(index)), index=index) | ||
MarcoGorelli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expected = pd.DataFrame(range(len(index[:3])), index=index[:3]) | ||
MarcoGorelli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
tm.assert_frame_equal(df["2012-01-01":"2012-01-04"], expected) | ||
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. Could you define |
||
|
||
def test_slice_datetime_index(self): | ||
# GH35509 | ||
df = pd.DataFrame( | ||
MarcoGorelli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{"col1": ["a", "b", "c"], "col2": [1, 2, 3]}, | ||
index=pd.to_datetime(["2020-08-01", "2020-07-02", "2020-08-05"]), | ||
) | ||
expected = pd.DataFrame( | ||
MarcoGorelli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{"col1": ["a", "c"], "col2": [1, 3]}, | ||
index=pd.to_datetime(["2020-08-01", "2020-08-05"]), | ||
) | ||
tm.assert_frame_equal(df.loc["2020-08"], expected) | ||
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. Could you define |
Uh oh!
There was an error while loading. Please reload this page.