8000 REF: implement _wrap_reduction_result by jbrockmendel · Pull Request #37660 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

REF: implement _wrap_reduction_result #37660

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
merged 18 commits into from
Nov 8, 2020
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

8000
Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
follow-up clenaup
  • Loading branch information
jbrockmendel committed Oct 27, 2020
commit 5bbc5d1a40f07acba5bae4f7777c4e67b0a7d066
10 changes: 2 additions & 8 deletions pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ def _wrap_results(result, dtype: DtypeObj, fill_value=None):
assert not isna(fill_value), "Expected non-null fill_value"
if result == fill_value:
result = np.nan

if tz is not None:
# we get here e.g. via nanmean when we call it on a DTA[tz]
result = Timestamp(result, tz=tz)
Expand Down Expand Up @@ -934,8 +935,6 @@ def reduction(
)

datetimelike = orig_values.dtype.kind in ["m", "M"]
if datetimelike and mask is None:
mask = isna(orig_values)

if (axis is not None and values.shape[axis] == 0) or values.size == 0:
try:
Expand All @@ -950,12 +949,7 @@ def reduction(
result = _maybe_null_out(result, axis, mask, values.shape)

if datetimelike and not skipna:
if axis is None or values.ndim == 1:
if mask.any():
return orig_values.dtype.type("NaT")
else:
axis_mask = mask.any(axis=axis)
result[axis_mask] = orig_values.dtype.type("NaT")
result = _mask_datetimelike_result(result, axis, mask, orig_values)

return result

Expand Down
0