7
7
8
8
from pandas ._config import get_option
9
9
10
- from pandas ._libs import iNaT , lib , tslibs
10
+ from pandas ._libs import NaT , Timedelta , Timestamp , iNaT , lib
11
11
from pandas .compat ._optional import import_optional_dependency
12
12
13
13
from pandas .core .dtypes .cast import _int64_max , maybe_upcast_putmask
@@ -53,7 +53,7 @@ def __init__(self, *dtypes):
53
53
super ().__init__ ()
54
54
self .dtypes = tuple (pandas_dtype (dtype ).type for dtype in dtypes )
55
55
56
- def check (self , obj ):
56
+ def check (self , obj ) -> bool :
57
57
return hasattr (obj , "dtype" ) and issubclass (obj .dtype .type , self .dtypes )
58
58
59
59
def __call__ (self , f ):
@@ -128,7 +128,7 @@ def f(values, axis=None, skipna=True, **kwds):
128
128
return f
129
129
130
130
131
- def _bn_ok_dtype (dt , name ) :
131
+ def _bn_ok_dtype (dt , name : str ) -> bool :
132
132
# Bottleneck chokes on datetime64
133
133
if not is_object_dtype (dt ) and not (
134
134
is_datetime_or_timedelta_dtype (dt ) or is_datetime64tz_dtype (dt )
@@ -149,7 +149,7 @@ def _bn_ok_dtype(dt, name):
149
149
return False
150
150
151
151
152
- def _has_infs (result ):
152
+ def _has_infs (result ) -> bool :
153
153
if isinstance (result , np .ndarray ):
154
154
if result .dtype == "f8" :
155
155
return lib .has_infs_f8 (result .ravel ())
@@ -176,19 +176,22 @@ def _get_fill_value(dtype, fill_value=None, fill_value_typ=None):
176
176
return - np .inf
177
177
else :
178
178
if fill_value_typ is None :
179
- return tslibs . iNaT
179
+ return iNaT
180
180
else :
181
181
if fill_value_typ == "+inf" :
182
182
# need the max int here
183
183
return _int64_max
184
184
else :
185
- return tslibs . iNaT
185
+ return iNaT
186
186
187
187
188
188
def _maybe_get_mask (
189
189
values : np .ndarray , skipna : bool , mask : Optional [np .ndarray ]
190
190
) -> Optional [np .ndarray ]:
191
- """ This function will compute a mask iff it is necessary. Otherwise,
191
+ """
192
+ Compute a mask if and only if necessary.
193
+
194
+ This function will compute a mask iff it is necessary. Otherwise,
192
195
return the provided mask (potentially None) when a mask does not need to be
193
196
computed.
194
197
@@ -214,7 +217,6 @@ def _maybe_get_mask(
214
217
Returns
215
218
-------
216
219
Optional[np.ndarray]
217
-
218
220
"""
219
221
220
222
if mask is None :
@@ -346,7 +348,7 @@ def _wrap_results(result, dtype, fill_value=None):
346
348
assert not isna (fill_value ), "Expected non-null fill_value"
347
349
if result == fill_value :
348
350
result = np .nan
349
- result = tslibs . Timestamp (result , tz = tz )
351
+ result = Timestamp (result , tz = tz )
350
352
else :
351
353
result = result .view (dtype )
352
354
elif is_timedelta64_dtype (dtype ):
@@ -358,21 +360,22 @@ def _wrap_results(result, dtype, fill_value=None):
358
360
if np .fabs (result ) > _int64_max :
359
361
raise ValueError ("overflow in timedelta operation" )
360
362
361
- result = tslibs . Timedelta (result , unit = "ns" )
363
+ result = Timedelta (result , unit = "ns" )
362
364
else :
363
365
result = result .astype ("m8[ns]" ).view (dtype )
364
366
365
367
return result
366
368
367
369
368
- def _na_for_min_count (values , axis ):
369
- """Return the missing value for `values`
370
+ def _na_for_min_count (values , axis : Optional [int ]):
371
+ """
372
+ Return the missing value for `values`.
370
373
371
374
Parameters
372
375
----------
373
376
values : ndarray
374
377
axis : int or None
375
- axis for the reduction
378
+ axis for the reduction, required if values.ndim > 1.
376
379
377
380
Returns
378
381
-------
@@ -388,13 +391,14 @@ def _na_for_min_count(values, axis):
388
391
if values .ndim == 1 :
389
392
return fill_value
390
393
else :
394
+ assert axis is not None # assertion to make mypy happy
391
395
result_shape = values .shape [:axis ] + values .shape [axis + 1 :]
392
396
result = np .empty (result_shape , dtype = values .dtype )
393
397
result .fill (fill_value )
394
398
return result
395
399
396
400
397
- def nanany (values , axis = None , skipna = True , mask = None ):
401
+ def nanany (values , axis = None , skipna : bool = True , mask = None ):
398
402
"""
399
403
Check if any elements along an axis evaluate to True.
400
404
@@ -426,7 +430,7 @@ def nanany(values, axis=None, skipna=True, mask=None):
426
430
return values .any (axis )
427
431
428
432
429
- def nanall (values , axis = None , skipna = True , mask = None ):
433
+ def nanall (values , axis = None , skipna : bool = True , mask = None ):
430
434
"""
431
435
Check if all elements along an axis evaluate to True.
432
436
@@ -1195,7 +1199,7 @@ def _maybe_null_out(
1195
1199
else :
1196
1200
# GH12941, use None to auto cast null
1197
1201
result [null_mask ] = None
1198
- elif result is not tslibs . NaT :
1202
+ elif result is not NaT :
1199
1203
if mask is not None :
1200
1204
null_mask = mask .size - mask .sum ()
1201
1205
else :
0 commit comments