26
26
TD64NS_DTYPE ,
27
27
ensure_object ,
28
28
is_bool_dtype ,
29
- is_complex_dtype ,
30
29
is_dtype_equal ,
31
30
is_extension_array_dtype ,
32
- is_float_dtype ,
33
31
is_integer_dtype ,
34
32
is_object_dtype ,
35
33
is_scalar ,
36
34
is_string_or_object_np_dtype ,
37
- needs_i8_conversion ,
38
35
)
39
36
from pandas .core .dtypes .dtypes import (
40
37
CategoricalDtype ,
@@ -291,7 +288,7 @@ def _isna_array(values: ArrayLike, inf_as_na: bool = False):
291
288
result = values .isna () # type: ignore[assignment]
292
289
elif is_string_or_object_np_dtype (values .dtype ):
293
290
result = _isna_string_dtype (values , inf_as_na = inf_as_na )
294
- elif needs_i8_conversion ( dtype ) :
291
+ elif dtype . kind in "mM" :
295
292
# this is the NaT pattern
296
293
result = values .view ("i8" ) == iNaT
297
294
else :
@@ -502,7 +499,7 @@ def array_equivalent(
502
499
# fastpath when we require that the dtypes match (Block.equals)
503
500
if left .dtype .kind in "fc" :
504
501
return _array_equivalent_float (left , right )
505
- elif needs_i8_conversion ( left .dtype ) :
502
+ elif left .dtype . kind in "mM" :
506
503
return _array_equivalent_datetimelike (left , right )
507
504
elif is_string_or_object_np_dtype (left .dtype ):
508
505
# TODO: fastpath for pandas' StringDtype
@@ -519,14 +516,14 @@ def array_equivalent(
519
516
return _array_equivalent_object (left , right , strict_nan )
520
517
521
518
# NaNs can occur in float and complex arrays.
522
- if is_float_dtype ( left .dtype ) or is_complex_dtype ( left . dtype ) :
519
+ if left .dtype . kind in "fc" :
523
520
if not (left .size and right .size ):
524
521
return True
525
522
return ((left == right ) | (isna (left ) & isna (right ))).all ()
526
523
527
- elif needs_i8_conversion ( left .dtype ) or needs_i8_conversion ( right .dtype ) :
524
+ elif left .dtype . kind in "mM" or right .dtype . kind in "mM" :
528
525
# datetime64, timedelta64, Period
529
- if not is_dtype_equal ( left .dtype , right .dtype ) :
526
+ if left .dtype != right .dtype :
530
527
return False
531
528
532
529
left = left .view ("i8" )
@@ -541,11 +538,11 @@ def array_equivalent(
541
538
return np .array_equal (left , right )
542
539
543
540
544
- def _array_equivalent_float (left , right ) -> bool :
541
+ def _array_equivalent_float (left : np . ndarray , right : np . ndarray ) -> bool :
545
542
return bool (((left == right ) | (np .isnan (left ) & np .isnan (right ))).all ())
546
543
547
544
548
- def _array_equivalent_datetimelike (left , right ):
545
+ def _array_equivalent_datetimelike (left : np . ndarray , right : np . ndarray ):
549
546
return np .array_equal (left .view ("i8" ), right .view ("i8" ))
550
547
551
548
@@ -601,7 +598,7 @@ def infer_fill_value(val):
601
598
if not is_list_like (val ):
602
599
val = [val ]
603
600
val = np .array (val , copy = False )
604
- if needs_i8_conversion ( val .dtype ) :
601
+ if val .dtype . kind in "mM" :
605
602
return np .array ("NaT" , dtype = val .dtype )
606
603
elif is_object_dtype (val .dtype ):
607
604
dtype = lib .infer_dtype (ensure_object (val ), skipna = False )
@@ -616,7 +613,7 @@ def maybe_fill(arr: np.ndarray) -> np.ndarray:
616
613
"""
617
614
Fill numpy.ndarray with NaN, unless we have a integer or boolean dtype.
618
615
"""
619
- if arr .dtype .kind not in ( "u" , "i" , "b" ) :
616
+ if arr .dtype .kind not in "iub" :
620
617
arr .fill (np .nan )
621
618
return arr
622
619
@@ -650,15 +647,15 @@ def na_value_for_dtype(dtype: DtypeObj, compat: bool = True):
650
647
651
648
if isinstance (dtype , ExtensionDtype ):
652
649
return dtype .na_value
653
- elif needs_i8_conversion ( dtype ) :
650
+ elif dtype . kind in "mM" :
654
651
return dtype .type ("NaT" , "ns" )
655
- elif is_float_dtype ( dtype ) :
652
+ elif dtype . kind == "f" :
656
653
return np .nan
657
- elif is_integer_dtype ( dtype ) :
654
+ elif dtype . kind in "iu" :
658
655
if compat :
659
656
return 0
660
657
return np .nan
661
- elif is_bool_dtype ( dtype ) :
658
+ elif dtype . kind == "b" :
662
659
if compat :
663
660
return False
664
661
return np .nan
0 commit comments