Skip to content

Commit 151b6e0

Browse files
TYP: check_untyped_defs pandas.core.nanops (#34689)
1 parent 98d28e3 commit 151b6e0

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

pandas/core/nanops.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def __init__(self, name=None, **kwargs):
8686
self.name = name
8787
self.kwargs = kwargs
8888

89-
def __call__(self, alt):
89+
def __call__(self, alt: F) -> F:
9090
bn_name = self.name or alt.__name__
9191

9292
try:
@@ -130,7 +130,7 @@ def f(
130130

131131
return result
132132

133-
return f
133+
return cast(F, f)
134134

135135

136136
def _bn_ok_dtype(dtype: DtypeObj, name: str) -> bool:
@@ -514,7 +514,12 @@ def nansum(
514514

515515
@disallow(PeriodDtype)
516516
@bottleneck_switch()
517-
def nanmean(values, axis=None, skipna=True, mask=None):
517+
def nanmean(
518+
values: np.ndarray,
519+
axis: Optional[int] = None,
520+
skipna: bool = True,
521+
mask: Optional[np.ndarray] = None,
522+
) -> float:
518523
"""
519524
Compute the mean of the element along an axis ignoring NaNs
520525
@@ -528,7 +533,7 @@ def nanmean(values, axis=None, skipna=True, mask=None):
528533
529534
Returns
530535
-------
531-
result : float
536+
float
532537
Unless input is a float array, in which case use the same
533538
precision as the input array.
534539
@@ -558,6 +563,7 @@ def nanmean(values, axis=None, skipna=True, mask=None):
558563
the_sum = _ensure_numeric(values.sum(axis, dtype=dtype_sum))
559564

560565
if axis is not None and getattr(the_sum, "ndim", False):
566+
count = cast(np.ndarray, count)
561567
with np.errstate(all="ignore"):
562568
# suppress division by zero warnings
563569
the_mean = the_sum / count
@@ -1205,17 +1211,17 @@ def _maybe_arg_null_out(
12051211

12061212

12071213
def _get_counts(
1208-
values_shape: Tuple[int],
1214+
values_shape: Tuple[int, ...],
12091215
mask: Optional[np.ndarray],
12101216
axis: Optional[int],
12111217
dtype: Dtype = float,
1212-
) -> Union[int, np.ndarray]:
1218+
) -> Union[int, float, np.ndarray]:
12131219
"""
12141220
Get the count of non-null values along an axis
12151221
12161222
Parameters
12171223
----------
1218-
values_shape : Tuple[int]
1224+
values_shape : tuple of int
12191225
shape tuple from values ndarray, used if mask is None
12201226
mask : Optional[ndarray[bool]]
12211227
locations in values that should be considered missing

setup.cfg

-3
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,6 @@ check_untyped_defs=False
208208
[mypy-pandas.core.missing]
209209
check_untyped_defs=False
210210

211-
[mypy-pandas.core.nanops]
212-
check_untyped_defs=False
213-
214211
[mypy-pandas.core.ops.docstrings]
215212
check_untyped_defs=False
216213

0 commit comments

Comments
 (0)