Skip to content

Commit b465714

Browse files
authored
TYP: annotations in nanops (#33935)
1 parent 6cdd211 commit b465714

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

pandas/core/nanops.py

+13-17
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pandas._config import get_option
99

1010
from pandas._libs import NaT, Timedelta, Timestamp, iNaT, lib
11-
from pandas._typing import ArrayLike, Dtype, F, Scalar
11+
from pandas._typing import ArrayLike, Dtype, DtypeObj, F, Scalar
1212
from pandas.compat._optional import import_optional_dependency
1313

1414
from pandas.core.dtypes.cast import _int64_max, maybe_upcast_putmask
@@ -133,7 +133,7 @@ def f(
133133
return f
134134

135135

136-
def _bn_ok_dtype(dtype: Dtype, name: str) -> bool:
136+
def _bn_ok_dtype(dtype: DtypeObj, name: str) -> bool:
137137
# Bottleneck chokes on datetime64, PeriodDtype (or and EA)
138138
if not is_object_dtype(dtype) and not needs_i8_conversion(dtype):
139139

@@ -166,7 +166,7 @@ def _has_infs(result) -> bool:
166166

167167

168168
def _get_fill_value(
169-
dtype: Dtype, fill_value: Optional[Scalar] = None, fill_value_typ=None
169+
dtype: DtypeObj, fill_value: Optional[Scalar] = None, fill_value_typ=None
170170
):
171171
""" return the correct fill value for the dtype of the values """
172172
if fill_value is not None:
@@ -270,9 +270,9 @@ def _get_values(
270270
Potential copy of input value array
271271
mask : Optional[ndarray[bool]]
272272
Mask for values, if deemed necessary to compute
273-
dtype : dtype
273+
dtype : np.dtype
274274
dtype for values
275-
dtype_max : dtype
275+
dtype_max : np.dtype
276276
platform independent dtype
277277
fill_value : Any
278278
fill value used
@@ -312,20 +312,20 @@ def _get_values(
312312
# return a platform independent precision dtype
313313
dtype_max = dtype
314314
if is_integer_dtype(dtype) or is_bool_dtype(dtype):
315-
dtype_max = np.int64
315+
dtype_max = np.dtype(np.int64)
316316
elif is_float_dtype(dtype):
317-
dtype_max = np.float64
317+
dtype_max = np.dtype(np.float64)
318318

319319
return values, mask, dtype, dtype_max, fill_value
320320

321321

322-
def _na_ok_dtype(dtype) -> bool:
322+
def _na_ok_dtype(dtype: DtypeObj) -> bool:
323323
if needs_i8_conversion(dtype):
324324
return False
325325
return not issubclass(dtype.type, np.integer)
326326

327327

328-
def _wrap_results(result, dtype: Dtype, fill_value=None):
328+
def _wrap_results(result, dtype: DtypeObj, fill_value=None):
329329
""" wrap our results if needed """
330330
if is_datetime64_any_dtype(dtype):
331331
if fill_value is None:
@@ -597,7 +597,7 @@ def get_median(x):
597597
return np.nan
598598
return np.nanmedian(x[mask])
599599

600-
values, mask, dtype, dtype_max, _ = _get_values(values, skipna, mask=mask)
600+
values, mask, dtype, _, _ = _get_values(values, skipna, mask=mask)
601601
if not is_float_dtype(values.dtype):
602602
try:
603603
values = values.astype("f8")
@@ -716,7 +716,7 @@ def nanstd(values, axis=None, skipna=True, ddof=1, mask=None):
716716
1.0
717717
"""
718718
orig_dtype = values.dtype
719-
values, mask, dtype, dtype_max, fill_value = _get_values(values, skipna, mask=mask)
719+
values, mask, _, _, _ = _get_values(values, skipna, mask=mask)
720720

721721
result = np.sqrt(nanvar(values, axis=axis, skipna=skipna, ddof=ddof, mask=mask))
722722
return _wrap_results(result, orig_dtype)
@@ -910,9 +910,7 @@ def nanargmax(
910910
>>> nanops.nanargmax(arr, axis=1)
911911
array([2, 2, 1, 1], dtype=int64)
912912
"""
913-
values, mask, dtype, _, _ = _get_values(
914-
values, True, fill_value_typ="-inf", mask=mask
915-
)
913+
values, mask, _, _, _ = _get_values(values, True, fill_value_typ="-inf", mask=mask)
916914
result = values.argmax(axis)
917915
result = _maybe_arg_null_out(result, axis, mask, skipna)
918916
return result
@@ -956,9 +954,7 @@ def nanargmin(
956954
>>> nanops.nanargmin(arr, axis=1)
957955
array([0, 0, 1, 1], dtype=int64)
958956
"""
959-
values, mask, dtype, _, _ = _get_values(
960-
values, True, fill_value_typ="+inf", mask=mask
961-
)
957+
values, mask, _, _, _ = _get_values(values, True, fill_value_typ="+inf", mask=mask)
962958
result = values.argmin(axis)
963959
result = _maybe_arg_null_out(result, axis, mask, skipna)
964960
return result

0 commit comments

Comments
 (0)