-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fix first_last_valid_index, now preserves the frequency. #20569
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
pandas/core/generic.py
Outdated
@@ -8763,6 +8763,51 @@ def transform(self, func, *args, **kwargs): | |||
scalar : type of index | |||
""" | |||
|
|||
def _find_first_valid(self, reversed=False): |
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 rename to _find_valid_index
and make the param (required), and call it how='first'|'last'
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.
cool, looks better.
pandas/core/generic.py
Outdated
i = is_valid.idxmax() | ||
if not is_valid[i]: | ||
return None | ||
else: |
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.
don't need the elses (just return)
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.
hmmmm, I'm not sure, I was thinking about the case when there is no valid values (all nans), In that case this function returns the first index when should be None
.
pandas/core/generic.py
Outdated
return None | ||
else: | ||
return i | ||
else: |
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.
don't need the else
pandas/core/generic.py
Outdated
if not is_valid.iat[len(self) - i - 1]: | ||
return None | ||
else: | ||
return self.index[len(self) - i - 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.
same
can you add a whatsnew note as well |
@jreback of course, also I forgot asking you where I should add the whatsnew note. |
Removed old methods from Series and DF Added new methods into NDFrame Created new convenient method _find_first_valid
Codecov Report
@@ Coverage Diff @@
## master #20569 +/- ##
==========================================
- Coverage 91.84% 91.84% -0.01%
==========================================
Files 152 152
Lines 49270 49262 -8
==========================================
- Hits 45252 45243 -9
- Misses 4018 4019 +1
Continue to review full report at Codecov.
|
@jreback I added whatsnew note under "Bug fixes: Indexing" section. |
thanks @mmngreco |
Checklist
git diff upstream/master -u -- "*.py" | flake8 --diff
I'm not sure if I should add a test somewhere else. Notice that I've added a new function
_find_first_valid
.