-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: fixes indexing with monotonic decreasing DTI (#19362) #20677
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
Conversation
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.
pls add a whatsnew note (indexing bug fix section)
pandas/core/indexes/datetimelike.py
Outdated
@@ -342,7 +342,7 @@ def _format_with_header(self, header, **kwargs): | |||
def __contains__(self, key): | |||
try: | |||
res = self.get_loc(key) | |||
return is_scalar(res) or type(res) == slice or np.any(res) | |||
return is_scalar(res) or type(res) == slice or np.any(res + 1) |
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 change type(res) == slice
to isinstance(res, slice)
.
I think condition could be (for the last clause)
is_list_like(res) and len(res)
. just need to account for an indexer, not the character of it
df = pd.DataFrame({'A': [1, 2, 3]}, | ||
index=pd.date_range('20170101', | ||
periods=3)[::-1]) | ||
df.loc['2017-01-03'] |
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 assert on the result of this
@@ -252,3 +252,11 @@ def test_series_partial_set_period(self): | |||
check_stacklevel=False): | |||
result = ser.loc[keys] | |||
tm.assert_series_equal(result, exp) | |||
|
|||
def test_monotone_DTI_indexing_bug(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.
this test belongs in one of:
pandas/tests/indexes/datetimes/test_datetime.py
pandas/tests/indexes/datetimes/test_partial_slicing.py
Codecov Report
@@ Coverage Diff @@
## master #20677 +/- ##
=========================================
Coverage ? 91.81%
=========================================
Files ? 153
Lines ? 49279
Branches ? 0
=========================================
Hits ? 45247
Misses ? 4032
Partials ? 0
Continue to review full report at Codecov.
|
Thanks for the helpful comments @jreback, I think the updated commit should address the points. |
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.
lgtm. some small comments. ping on green.
@@ -368,3 +368,14 @@ def test_factorize_dst(self): | |||
def test_unique(self, arr, expected): | |||
result = arr.unique() | |||
tm.assert_index_equal(result, 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.
can you move near the other tests?
also can you add all of the examples from the original issue (e.g. the working ones). so this is a complete example.
can you add a comment on what is being tested here.
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 move near the other tests?
Sorry, didn't quite get this one, but tried to move this closer to other tests that seem a little similar.
also can you add all of the examples from the original issue (e.g. the working ones). so this is a complete example.
There wasn't a lot of stuff in the original issue, but I added what the person who posted that issue was attempting to do.
can you add a comment on what is being tested here.
Added a short comment.
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.
pandas/core/indexes/datetimelike.py
Outdated
@@ -342,7 +342,8 @@ def _format_with_header(self, header, **kwargs): | |||
def __contains__(self, key): | |||
try: | |||
res = self.get_loc(key) | |||
return is_scalar(res) or type(res) == slice or np.any(res) | |||
return is_scalar(res) or isinstance(res, slice) or \ |
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.
Typically we use parenthesis to break long lines, not \
.
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.
Changed that, also fixed the conflict.
thanks @mapehe! |
Np! |
git diff upstream/master -u -- "*.py" | flake8 --diff
Seems that #19362 is caused by the fact that
np.any([0])
is false. Here's a suggested solution. Also added a test.