-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
API: make min/max on empty datetime df consistent with datetime serie… #33911
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
jreback
merged 12 commits into
pandas-dev:master
from
CloseChoice:API-consistent-empty-datetime-max-or-min
May 9, 2020
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6c255d0
API: make min/max on empty datetime df consistent with datetime serie…
CloseChoice 363898d
update nanops and tests as result of PR discussion
CloseChoice 0d9a754
removed git tracking of test file
CloseChoice 6e14ff8
removed git tracking of test file
CloseChoice 60ea00f
added whatsnew entry
CloseChoice 5e57597
move tests to test_analytics.py
CloseChoice c62921b
removed blank line at-end-of-file test_analytics.py
CloseChoice b958e29
Merge branch 'master' into API-consistent-empty-datetime-max-or-min
CloseChoice e309459
Merge branch 'master' of https://github.com/pandas-dev/pandas into AP…
CloseChoice 77fd5c6
splitted tests, update comment in nanops and update whatsnew entry
CloseChoice 9219ec3
update test_analytics for linting
CloseChoice 6dfec8f
Merge branch 'master' of https://github.com/pandas-dev/pandas into AP…
CloseChoice 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -1258,3 +1258,30 @@ def test_min_max_dt64_with_NaT(self): | |
res = df.max() | ||
exp = pd.Series([pd.NaT], index=["foo"]) | ||
tm.assert_series_equal(res, exp) | ||
|
||
def test_min_max_dt64_api_consistency_with_NaT(self): | ||
# Calling the following sum functions returned an error for dataframes but | ||
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. make a new test 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. done |
||
# returned NaT for series. These tests check that the API is consistent in | ||
# min/max calls on empty Series/DataFrames. See GH:33704 for more | ||
# information | ||
df = pd.DataFrame(dict(x=pd.to_datetime([]))) | ||
expected_dt_series = pd.Series(pd.to_datetime([])) | ||
# check axis 0 | ||
assert (df.min(axis=0).x is pd.NaT) == (expected_dt_series.min() is pd.NaT) | ||
assert (df.max(axis=0).x is pd.NaT) == (expected_dt_series.max() is pd.NaT) | ||
|
||
# check axis 1 | ||
tm.assert_series_equal(df.min(axis=1), expected_dt_series) | ||
tm.assert_series_equal(df.max(axis=1), expected_dt_series) | ||
|
||
def test_min_max_dt64_api_consistency_empty_df(self): | ||
# check DataFrame/Series api consistency when calling min/max on an empty | ||
# DataFrame/Series. | ||
df = pd.DataFrame(dict(x=[])) | ||
expected_float_series = pd.Series([], dtype=float) | ||
# check axis 0 | ||
assert np.isnan(df.min(axis=0).x) == np.isnan(expected_float_series.min()) | ||
assert np.isnan(df.max(axis=0).x) == np.isnan(expected_float_series.max()) | ||
# check axis 1 | ||
tm.assert_series_equal(df.min(axis=1), expected_float_series) | ||
tm.assert_series_equal(df.min(axis=1), expected_float_series) |
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 hits each of these branches?
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.
when
np.full
is called with the parameterdtype=np.datetime64
andfill_value=pd.NaT
a ValueErrorValueError: cannot convert float NaN to integer
. In this case I don't callnp.full
without an explicitdtype
. Giving the arrayresult
an explicit dtype does not have an effect on the DataFrame column but I thought it is cleaner if I at least try to give it the correct one. I hoped the comment explains this. But if not, I'm gonna make it gonna improve the comment.