Skip to content

TYP: follow-up to #37723 #37745

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 2 commits into from
Nov 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,21 @@ def _wrap_results(result, dtype: np.dtype, fill_value=None):
return result


def _datetimelike_compat(func):
def _datetimelike_compat(func: F) -> F:
"""
If we have datetime64 or timedelta64 values, ensure we have a correct
mask before calling the wrapped function, then cast back afterwards.
"""

@functools.wraps(func)
def new_func(values, *, axis=None, skipna=True, mask=None, **kwargs):
def new_func(
values: np.ndarray,
*,
axis: Optional[int] = None,
skipna: bool = True,
mask: Optional[np.ndarray] = None,
**kwargs,
):
orig_values = values

datetimelike = values.dtype.kind in ["m", "M"]
Expand All @@ -390,7 +397,7 @@ def new_func(values, *, axis=None, skipna=True, mask=None, **kwargs):

return result

return new_func
return cast(F, new_func)


def _na_for_min_count(
Expand Down