|
7 | 7 |
|
8 | 8 | from pandas._config import get_option
|
9 | 9 |
|
10 |
| -from pandas._libs import NaT, Period, Timedelta, Timestamp, iNaT, lib |
| 10 | +from pandas._libs import NaT, Timedelta, Timestamp, iNaT, lib |
11 | 11 | from pandas._typing import ArrayLike, Dtype, Scalar
|
12 | 12 | from pandas.compat._optional import import_optional_dependency
|
13 | 13 |
|
@@ -353,14 +353,6 @@ def _wrap_results(result, dtype: Dtype, fill_value=None):
|
353 | 353 | else:
|
354 | 354 | result = result.astype("m8[ns]").view(dtype)
|
355 | 355 |
|
356 |
| - elif isinstance(dtype, PeriodDtype): |
357 |
| - if is_float(result) and result.is_integer(): |
358 |
| - result = int(result) |
359 |
| - if is_integer(result): |
360 |
| - result = Period._from_ordinal(result, freq=dtype.freq) |
361 |
| - else: |
362 |
| - raise NotImplementedError(type(result), result) |
363 |
| - |
364 | 356 | return result
|
365 | 357 |
|
366 | 358 |
|
@@ -516,6 +508,7 @@ def nansum(
|
516 | 508 | return _wrap_results(the_sum, dtype)
|
517 | 509 |
|
518 | 510 |
|
| 511 | +@disallow(PeriodDtype) |
519 | 512 | @bottleneck_switch()
|
520 | 513 | def nanmean(values, axis=None, skipna=True, mask=None):
|
521 | 514 | """
|
@@ -547,7 +540,12 @@ def nanmean(values, axis=None, skipna=True, mask=None):
|
547 | 540 | )
|
548 | 541 | dtype_sum = dtype_max
|
549 | 542 | dtype_count = np.float64
|
550 |
| - if is_integer_dtype(dtype) or needs_i8_conversion(dtype): |
| 543 | + # not using needs_i8_conversion because that includes period |
| 544 | + if ( |
| 545 | + is_integer_dtype(dtype) |
| 546 | + or is_datetime64_any_dtype(dtype) |
| 547 | + or is_timedelta64_dtype(dtype) |
| 548 | + ): |
551 | 549 | dtype_sum = np.float64
|
552 | 550 | elif is_float_dtype(dtype):
|
553 | 551 | dtype_sum = dtype
|
|
0 commit comments