Skip to content

Commit 8c7fcf8

Browse files
jbrockmendelKevin D Smith
authored and
Kevin D Smith
committed
CLN: nanops (pandas-dev#37396)
1 parent 1a677d7 commit 8c7fcf8

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

pandas/core/nanops.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -381,18 +381,16 @@ def _na_for_min_count(
381381
if is_numeric_dtype(values):
382382
values = values.astype("float64")
383383
fill_value = na_value_for_dtype(values.dtype)
384+
if fill_value is NaT:
385+
fill_value = values.dtype.type("NaT", "ns")
384386

385387
if values.ndim == 1:
386388
return fill_value
387389
else:
388390
assert axis is not None # assertion to make mypy happy
389391
result_shape = values.shape[:axis] + values.shape[axis + 1 :]
390-
# calling np.full with dtype parameter throws an ValueError when called
391-
# with dtype=np.datetime64 and and fill_value=pd.NaT
392-
try:
393-
result = np.full(result_shape, fill_value, dtype=values.dtype)
394-
except ValueError:
395-
result = np.full(result_shape, fill_value)
392+
393+
result = np.full(result_shape, fill_value, dtype=values.dtype)
396394
return result
397395

398396

@@ -526,11 +524,9 @@ def nansum(
526524
def _mask_datetimelike_result(
527525
result: Union[np.ndarray, np.datetime64, np.timedelta64],
528526
axis: Optional[int],
529-
mask: Optional[np.ndarray],
527+
mask: np.ndarray,
530528
orig_values: np.ndarray,
531529
):
532-
if mask is None:
533-
mask = isna(orig_values)
534530
if isinstance(result, np.ndarray):
535531
# we need to apply the mask
536532
result = result.astype("i8").view(orig_values.dtype)

0 commit comments

Comments
 (0)