-
-
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
Changes from 4 commits
6c255d0
363898d
0d9a754
6e14ff8
60ea00f
5e57597
c62921b
b958e29
e309459
77fd5c6
9219ec3
6dfec8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1035,6 +1035,31 @@ def test_minmax_nat_dataframe(self, nat_df): | |
assert nat_df.min(skipna=False)[0] is pd.NaT | ||
assert nat_df.max(skipna=False)[0] is pd.NaT | ||
|
||
def test_min_max_dt64_with_NaT(self): | ||
# Calling the following sum functions returned an error for dataframes but | ||
# 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 NaT) == (expected_dt_series.min() is NaT) | ||
assert (df.max(axis=0).x is NaT) == (expected_dt_series.max() is NaT) | ||
|
||
# check axis 1 | ||
tm.assert_series_equal(df.min(axis=1), expected_dt_series) | ||
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. I just want to mention that calling |
||
tm.assert_series_equal(df.max(axis=1), expected_dt_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) | ||
|
||
def test_min_max(self): | ||
rng = pd.date_range("1/1/2000", "12/31/2000") | ||
rng2 = rng.take(np.random.permutation(len(rng))) | ||
|
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.