-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
REGR: fix bug in DatetimeIndex slicing with irregular or unsorted indices #37023
REGR: fix bug in DatetimeIndex slicing with irregular or unsorted indices #37023
Conversation
Hello @CloseChoice! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2020-10-26 12:55:55 UTC |
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.
Thanks @CloseChoice for the PR!
Some comments.
Can you add the OP from #35509? As per #36953 (comment) the two issues are caused by the same underlying bug but different behaviors so we'd like to have tests for both
I'm also not sure about the current location for this. Haven't looked in detail but somewhere like pandas/tests/frame/test_timeseries.py
might be more appropriate
pandas/tests/generic/test_generic.py
Outdated
|
||
def test_slice_incomplete_datetimes(self): | ||
# GH36953 and GH35509 | ||
increment = pd.Series( |
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.
I know this is the OP but is it possible to explicitly construct it? without using the cumsum
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.
done
Hi @arw2019 thanks for the quick review. I added another test corresponding to #35509 and moved both tests to your suggested destination |
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.
Thanks @CloseChoice can you add a release note to doc/source/whatsnew/v1.1.4.rst
@@ -63,3 +63,22 @@ def test_datetime_assignment_with_NaT_and_diff_time_units(self): | |||
{0: [1, None], "new": [1e9, None]}, dtype="datetime64[ns]" | |||
) | |||
tm.assert_frame_equal(result, expected) | |||
|
|||
def test_slice_irregular_datetime_index_with_nan(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.
move these to pandas/tests/indexing/test_partial.py
always use
result=
expected=
tm.assert_.....
also this needs a whatsnew note for 1.1.4 in regressions (mention both issues) |
index = pd.to_datetime(["2012-01-01", "2012-01-02", "2012-01-03", None]) | ||
df = pd.DataFrame(range(len(index)), index=index) | ||
expected = pd.DataFrame(range(len(index[:3])), index=index[:3]) | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Could you define result = df["2012-01-01":"2012-01-04"]
above?
{"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 comment
The reason will be displayed to describe this comment to others. Learn more.
Could you define result = df["2020-08"]
above?
pandas/core/generic.py
Outdated
@@ -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 comment
The 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 comment
The 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 comment
The 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?
…G-regression-datetimeindex-slicing
…tetimeindex-slicing
@CloseChoice can you fix the pre-commit errors. (I'm on Windows and pre-commit fails to initialize and these checks can no longer be performed locally from code-checks.sh #37240) cc @MarcoGorelli |
@CloseChoice you just need to replace @simonjayhawkins what errors do you get? Part of the motivation for moving these checks over to pre-commit was that they'd be cross-platform EDIT@simonjayhawkins the pre-commit hooks all pass, it's the code-checks.sh that fail 🤣 |
version information
error information
I understand that, but didn't we discuss that pre-commit was optional.
my bad. missed that. |
@simonjayhawkins thanks for the traceback - are you using conda? I could reproduce that on a windows conda environment. Looks like it's a bug in virtualenv pypa/virtualenv#1986 If you downgrade virtualenv to 20.0.33 then it should work (did for me) - if it works for you I'll note it in the docs |
thanks works for me too. (20.0.35 was installed). just started running on all-files. will report back if fails. |
back to the issue
failures on Windows py38_np18 seen on other PRs. |
thanks @CloseChoice |
…with irregular or unsorted indices
although it installed fine for me, some hooks still failed, likely because currently we have
instead of
, will fix |
works for me in anaconda prompt and git bash |
…ular or unsorted indices (#37418) Co-authored-by: Tobias Pitters <31857876+CloseChoice@users.noreply.github.com>
closes #36953
closes #35509
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff