-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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 8 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 |
---|---|---|
|
@@ -384,8 +384,12 @@ def _na_for_min_count( | |
else: | ||
assert axis is not None # assertion to make mypy happy | ||
result_shape = values.shape[:axis] + values.shape[axis + 1 :] | ||
result = np.empty(result_shape, dtype=values.dtype) | ||
result.fill(fill_value) | ||
# calling np.full with dtype parameter throws an ValueError when called | ||
# with np.datetime64 and pd.NaT | ||
try: | ||
result = np.full(result_shape, fill_value, dtype=values.dtype) | ||
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. what hits each of these branches? 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. when |
||
except ValueError: | ||
result = np.full(result_shape, fill_value) | ||
return result | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1258,3 +1258,26 @@ def test_min_max_dt64_with_NaT(self): | |
res = df.max() | ||
exp = pd.Series([pd.NaT], index=["foo"]) | ||
tm.assert_series_equal(res, exp) | ||
|
||
# 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) | ||
|
||
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) |
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.
can you make a userfacing note. IOW a user wants to know, what changed. you are referring to an internal routine.
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.
done