Skip to content

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

Merged
merged 2 commits into from
Sep 23, 2017
Merged

BUG: DataFrame.first_valid_index() fails if there is no valid entry. #17488

merged 2 commits into from
Sep 23, 2017

Conversation

skwbc
Copy link
Contributor

@skwbc skwbc commented Sep 10, 2017

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 and Series.

Also fixed same issue on DataFrame.last_valid_index().
Add docstrings to both methods of DataFrame and Series.

Closes #17400
@codecov
Copy link

codecov bot commented Sep 10, 2017

Codecov Report

Merging #17488 into master will decrease coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 88.92% <100%> (ø) ⬆️
#single 40.22% <14.28%> (-0.07%) ⬇️
Impacted Files Coverage Δ
pandas/core/series.py 94.95% <ø> (ø) ⬆️
pandas/core/frame.py 97.72% <100%> (-0.1%) ⬇️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fdbc6b8...144de64. Read the comment docs.

@codecov
Copy link

codecov bot commented Sep 10, 2017

Codecov Report

Merging #17488 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 88.94% <100%> (+0.02%) ⬆️
#single 40.22% <50%> (-0.07%) ⬇️
Impacted Files Coverage Δ
pandas/core/generic.py 91.99% <100%> (ø) ⬆️
pandas/core/frame.py 97.72% <100%> (-0.1%) ⬇️
pandas/core/series.py 94.95% <100%> (ø) ⬆️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/plotting/_converter.py 65.05% <0%> (+1.81%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 46856c3...6e974cb. Read the comment docs.

@gfyoung gfyoung added Bug Error Reporting Incorrect or improved errors from pandas Indexing Related to indexing on series/frames, not to indexes themselves labels Sep 10, 2017
Copy link
Contributor

@jreback jreback left a 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.

@@ -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`)
Copy link
Contributor

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

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.
Copy link
Contributor

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

Copy link
Contributor

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)

0

When all elements in first row are null, returns second index.

Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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)

@pep8speaks
Copy link

pep8speaks commented Sep 11, 2017

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.
@jreback jreback merged commit 85a1067 into pandas-dev:master Sep 23, 2017
@jreback
Copy link
Contributor

jreback commented Sep 23, 2017

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Error Reporting Incorrect or improved errors from pandas Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

df.first_valid_index() fails if there is no valid entry.
4 participants