-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
REF: stronger typing in _box_func #46917
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 all commits
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 |
---|---|---|
|
@@ -16,7 +16,6 @@ | |
from pandas._libs import ( | ||
NaT, | ||
NaTType, | ||
Timedelta, | ||
iNaT, | ||
lib, | ||
) | ||
|
@@ -367,19 +366,23 @@ def _wrap_results(result, dtype: np.dtype, fill_value=None): | |
result = np.datetime64("NaT", "ns") | ||
else: | ||
result = np.int64(result).view("datetime64[ns]") | ||
# retain original unit | ||
result = result.astype(dtype, copy=False) | ||
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. So do these changes make things internally More Correct and not necessarily have an external behavior change? 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. not user-facing unless they are directly using nanops, which they shouldnt be |
||
else: | ||
# If we have float dtype, taking a view will give the wrong result | ||
result = result.astype(dtype) | ||
elif is_timedelta64_dtype(dtype): | ||
if not isinstance(result, np.ndarray): | ||
if result == fill_value: | ||
result = np.nan | ||
if result == fill_value or np.isnan(result): | ||
result = np.timedelta64("NaT").astype(dtype) | ||
|
||
# raise if we have a timedelta64[ns] which is too large | ||
if np.fabs(result) > lib.i8max: | ||
elif np.fabs(result) > lib.i8max: | ||
# raise if we have a timedelta64[ns] which is too large | ||
raise ValueError("overflow in timedelta operation") | ||
else: | ||
# return a timedelta64 with the original unit | ||
result = np.int64(result).astype(dtype, copy=False) | ||
|
||
result = Timedelta(result, unit="ns") | ||
else: | ||
result = result.astype("m8[ns]").view(dtype) | ||
|
||
|
@@ -641,7 +644,7 @@ def _mask_datetimelike_result( | |
result[axis_mask] = iNaT # type: ignore[index] | ||
else: | ||
if mask.any(): | ||
return NaT | ||
return np.int64(iNaT).view(orig_values.dtype) | ||
return result | ||
|
||
|
||
|
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.
is this guaranteed true? e.g. can the input be a Timestamp
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 nanops changes fix the only places where we call _box_func with incorrect scalars