-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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: Fixes first_valid_index when DataFrame or Series has duplicate row index (GH21441) #21497
Merged
Merged
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
6151181
Initial commit
KalyanGokhale 003f801
Removed failing test from closed PR
KalyanGokhale 952758a
Updated logic
KalyanGokhale 1f4beb0
Changed logic from AND to OR for chk_notna
KalyanGokhale 675201d
Series reverse logic for how == last, edits to whatsnew
KalyanGokhale 0640279
Reverting how==last logic to original, restoring deleted test
KalyanGokhale 177a3f4
Fixed the if / for for chk_notna, added test cases for NA values in d…
KalyanGokhale e94aad5
Initial commit
KalyanGokhale ff58ffd
Removed failing test from closed PR
KalyanGokhale d326b0a
Updated logic
KalyanGokhale b53bb11
Changed logic from AND to OR for chk_notna
KalyanGokhale 0cb3405
Series reverse logic for how == last, edits to whatsnew
KalyanGokhale 11edb51
Reverting how==last logic to original, restoring deleted test
KalyanGokhale ed410e1
Fixed the if / for for chk_notna, added test cases for NA values in d…
KalyanGokhale 05e8a99
Rebased and updated whatsnew
KalyanGokhale 01a9f7e
Moved tests to test_timeseries
KalyanGokhale cbcb089
Rebased and whatsnew
KalyanGokhale 111efb0
Removed tests from test_generic
KalyanGokhale 608c09e
Updated test parameter name
KalyanGokhale d8fface
Minor update to whatsnew to force TravisCI build
KalyanGokhale 751046d
Mirrored logic for how == first and last
KalyanGokhale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -506,7 +506,15 @@ def test_asfreq_fillvalue(self): | |
actual_series = ts.asfreq(freq='1S', fill_value=9.0) | ||
assert_series_equal(expected_series, actual_series) | ||
|
||
def test_first_last_valid(self): | ||
@pytest.mark.parametrize("data,idx,expected_first,expected_last", [ | ||
({'A': [1, 2, 3]}, [1, 1, 2], 1, 2), | ||
({'A': [1, 2, 3]}, [1, 2, 2], 1, 2), | ||
({'A': [1, 2, 3, 4]}, ['d', 'd', 'd', 'd'], 'd', 'd'), | ||
({'A': [1, np.nan, 3]}, [1, 1, 2], 1, 2), | ||
({'A': [np.nan, np.nan, 3]}, [1, 1, 2], 2, 2), | ||
({'A': [1, np.nan, 3]}, [1, 2, 2], 1, 2)]) | ||
def test_first_last_valid(self, data, idx, | ||
expected_first, expected_last): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved tests here from |
||
N = len(self.frame.index) | ||
mat = randn(N) | ||
mat[:5] = nan | ||
|
@@ -539,6 +547,11 @@ def test_first_last_valid(self): | |
assert frame.first_valid_index().freq == frame.index.freq | ||
assert frame.last_valid_index().freq == frame.index.freq | ||
|
||
# GH 21441 | ||
df = DataFrame(data, index=idx) | ||
assert expected_first == df.first_valid_index() | ||
assert expected_last == df.last_valid_index() | ||
|
||
def test_first_subset(self): | ||
ts = tm.makeTimeDataFrame(freq='12h') | ||
result = ts.first('10d') | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
what are you trying to do 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.
Thanks - this block is supposed to check that for multiple counts of same index, at least one is not NA.
However, while testing this with following data, the expected output is not being returned
Expected
1
, returnedNone
I'll rework this patch and commit again - Thanks again for the question prompt, it was fallacy of assumption on my part (had not checked explicitly for NaN value among the multiple 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.
the loop was incorrect leading to an error, not sure what I was thinking earlier :) - fixed now and committing
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.
Fixed - rebased and committed
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.
still not clear on the logic here, why can't this be a mirror of the 'last' logic?