-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: DataFrame.first_valid_index() fails if there is no valid entry. #17488
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
Also fixed same issue on DataFrame.last_valid_index(). Add docstrings to both methods of DataFrame and Series. Closes #17400
Codecov Report
@@ Coverage Diff @@
## master #17488 +/- ##
==========================================
- Coverage 91.15% 91.13% -0.02%
==========================================
Files 163 163
Lines 49534 49539 +5
==========================================
- Hits 45153 45149 -4
- Misses 4381 4390 +9
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #17488 +/- ##
==========================================
+ Coverage 91.15% 91.16% +<.01%
==========================================
Files 163 163
Lines 49534 49540 +6
==========================================
+ Hits 45153 45162 +9
+ Misses 4381 4378 -3
Continue to review full report at Codecov.
|
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. see if you can consolidate the docs a bit, so we don't repeat so much.
doc/source/whatsnew/v0.21.0.txt
Outdated
@@ -399,6 +399,7 @@ Indexing | |||
- Bug in ``CategoricalIndex`` reindexing in which specified indices containing duplicates were not being respected (:issue:`17323`) | |||
- Bug in intersection of ``RangeIndex`` with negative step (:issue:`17296`) | |||
- Bug in ``IntervalIndex`` where performing a scalar lookup fails for included right endpoints of non-overlapping monotonic decreasing indexes (:issue:`16417`, :issue:`17271`) | |||
- Bug in ``DataFrame.first_valid_index`` and ``DataFrame.last_valid_index`` when no valid entry (:issue:`17400`) |
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.
you can do
:meth:`DataFrame.first_valid_index`
and so on
pandas/core/frame.py
Outdated
def first_valid_index(self): | ||
""" | ||
Return label for first non-NA/null value | ||
Return index for first non-NA/null value. | ||
If all elements are non-NA/null, returns None. |
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.
Add these 2 last sentences to a Notes
section
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.
add a Returns
section (it returns a scalar)
pandas/core/frame.py
Outdated
0 | ||
|
||
When all elements in first row are null, returns second index. | ||
|
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.
ideally would like to move these doc-strings to core/generic.py
and use _shared_docs
. can you do that.
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.
@jreback
Thank you for your advice.
Modified the doc-strings with _shared_docs
.
Not sure to the manner of pandas doc-strings, please check it.
If it's ok, I will squash the 2nd commit to 1st one.
Note: I have no idea to share the doc-strings between Series
and DataFrames
with Examples, so I removed the examples.
@@ -440,6 +440,11 @@ def test_first_last_valid(self): | |||
assert empty.last_valid_index() is None | |||
assert empty.first_valid_index() is None | |||
|
|||
# GH17400 |
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.
add a comment (no valid entries)
Hello @skwbc! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on September 11, 2017 at 14:08 Hours UTC |
This commit will be squashed to previous commit.
thanks! |
Just checking the number of valid entries and if it's zero, return
None
.Also fixed same issue on
DataFrame.last_valid_index()
.Add docstrings to both methods of
DataFrame
andSeries
.git diff upstream/master -u -- "*.py" | flake8 --diff