@@ -112,8 +112,11 @@ def __init__(self, data, dtype=None, freq=None, copy=False):
112
112
113
113
@classmethod
114
114
def _simple_new (
115
- cls , values : np .ndarray , freq : Optional [BaseOffset ] = None , dtype = None
116
- ):
115
+ cls : Type [DatetimeLikeArrayT ],
116
+ values : np .ndarray ,
117
+ freq : Optional [BaseOffset ] = None ,
118
+ dtype = None ,
119
+ ) -> DatetimeLikeArrayT :
117
120
raise AbstractMethodError (cls )
118
121
119
122
@property
@@ -217,7 +220,7 @@ def _box_func(self, x):
217
220
"""
218
221
raise AbstractMethodError (self )
219
222
220
- def _box_values (self , values ):
223
+ def _box_values (self , values ) -> np . ndarray :
221
224
"""
222
225
apply box func to passed values
223
226
"""
@@ -416,7 +419,9 @@ def _values_for_factorize(self):
416
419
return self ._ndarray , iNaT
417
420
418
421
@classmethod
419
- def _from_factorized (cls , values , original ):
422
+ def _from_factorized (
423
+ cls : Type [DatetimeLikeArrayT ], values , original
424
+ ) -> DatetimeLikeArrayT :
420
425
return cls (values , dtype = original .dtype )
421
426
422
427
# ------------------------------------------------------------------
@@ -661,7 +666,7 @@ def _unbox(
661
666
# These are not part of the EA API, but we implement them because
662
667
# pandas assumes they're there.
663
668
664
- def value_counts (self , dropna = False ):
669
+ def value_counts (self , dropna : bool = False ):
665
670
"""
666
671
Return a Series containing counts of unique values.
667
672
@@ -755,28 +760,30 @@ def isin(self, values) -> np.ndarray:
755
760
# ------------------------------------------------------------------
756
761
# Null Handling
757
762
758
- def isna (self ):
763
+ def isna (self ) -> np . ndarray :
759
764
return self ._isnan
760
765
761
766
@property # NB: override with cache_readonly in immutable subclasses
762
- def _isnan (self ):
767
+ def _isnan (self ) -> np . ndarray :
763
768
"""
764
769
return if each value is nan
765
770
"""
766
771
return self .asi8 == iNaT
767
772
768
773
@property # NB: override with cache_readonly in immutable subclasses
769
- def _hasnans (self ):
774
+ def _hasnans (self ) -> np . ndarray :
770
775
"""
771
776
return if I have any nans; enables various perf speedups
772
777
"""
773
778
return bool (self ._isnan .any ())
774
779
775
- def _maybe_mask_results (self , result , fill_value = iNaT , convert = None ):
780
+ def _maybe_mask_results (
781
+ self , result : np .ndarray , fill_value = iNaT , convert = None
782
+ ) -> np .ndarray :
776
783
"""
777
784
Parameters
778
785
----------
779
- result : a ndarray
786
+ result : np. ndarray
780
787
fill_value : object, default iNaT
781
788
convert : str, dtype or None
782
789
@@ -794,7 +801,7 @@ def _maybe_mask_results(self, result, fill_value=iNaT, convert=None):
794
801
result = result .astype (convert )
795
802
if fill_value is None :
796
803
fill_value = np .nan
797
- result [ self ._isnan ] = fill_value
804
+ np . putmask ( result , self ._isnan , fill_value )
798
805
return result
799
806
800
807
# ------------------------------------------------------------------
@@ -893,22 +900,24 @@ def _validate_frequency(cls, index, freq, **kwargs):
893
900
) from e
894
901
895
902
@classmethod
896
- def _generate_range (cls , start , end , periods , freq , * args , ** kwargs ):
903
+ def _generate_range (
904
+ cls : Type [DatetimeLikeArrayT ], start , end , periods , freq , * args , ** kwargs
905
+ ) -> DatetimeLikeArrayT :
897
906
raise AbstractMethodError (cls )
898
907
899
908
# monotonicity/uniqueness properties are called via frequencies.infer_freq,
900
909
# see GH#23789
901
910
902
911
@property
903
- def _is_monotonic_increasing (self ):
912
+ def _is_monotonic_increasing (self ) -> bool :
904
913
return algos .is_monotonic (self .asi8 , timelike = True )[0 ]
905
914
906
915
@property
907
- def _is_monotonic_decreasing (self ):
916
+ def _is_monotonic_decreasing (self ) -> bool :
908
917
return algos .is_monotonic (self .asi8 , timelike = True )[1 ]
909
918
910
919
@property
911
- def _is_unique (self ):
920
+ def _is_unique (self ) -> bool :
912
921
return len (unique1d (self .asi8 )) == len (self )
913
922
914
923
# ------------------------------------------------------------------
@@ -940,9 +949,10 @@ def _cmp_method(self, other, op):
940
949
result = op (self ._ndarray .view ("i8" ), other_vals .view ("i8" ))
941
950
942
951
o_mask = isna (other )
943
- if self ._hasnans | np .any (o_mask ):
952
+ mask = self ._isnan | o_mask
953
+ if mask .any ():
944
954
nat_result = op is operator .ne
945
- result [ self . _isnan | o_mask ] = nat_result
955
+ np . putmask ( result , mask , nat_result )
946
956
947
957
return result
948
958
@@ -996,7 +1006,7 @@ def _add_timedeltalike_scalar(self, other):
996
1006
if isna (other ):
997
1007
# i.e np.timedelta64("NaT"), not recognized by delta_to_nanoseconds
998
1008
new_values = np .empty (self .shape , dtype = "i8" )
999
- new_values [:] = iNaT
1009
+ new_values . fill ( iNaT )
1000
1010
return type (self )(new_values , dtype = self .dtype )
1001
1011
1002
1012
inc = delta_to_nanoseconds (other )
@@ -1038,7 +1048,7 @@ def _add_timedelta_arraylike(self, other):
1038
1048
)
1039
1049
if self ._hasnans or other ._hasnans :
1040
1050
mask = self ._isnan | other ._isnan
1041
- new_values [ mask ] = iNaT
1051
+ np . putmask ( new_values , mask , iNaT )
1042
1052
1043
1053
return type (self )(new_values , dtype = self .dtype )
1044
1054
@@ -1053,7 +1063,7 @@ def _add_nat(self):
1053
1063
1054
1064
# GH#19124 pd.NaT is treated like a timedelta for both timedelta
1055
1065
# and datetime dtypes
1056
- result = np .zeros (self .shape , dtype = np .int64 )
1066
+ result = np .empty (self .shape , dtype = np .int64 )
1057
1067
result .fill (iNaT )
1058
1068
return type (self )(result , dtype = self .dtype , freq = None )
1059
1069
@@ -1067,7 +1077,7 @@ def _sub_nat(self):
1067
1077
# For datetime64 dtypes by convention we treat NaT as a datetime, so
1068
1078
# this subtraction returns a timedelta64 dtype.
1069
1079
# For period dtype, timedelta64 is a close-enough return dtype.
1070
- result = np .zeros (self .shape , dtype = np .int64 )
1080
+ result = np .empty (self .shape , dtype = np .int64 )
1071
1081
result .fill (iNaT )
1072
1082
return result .view ("timedelta64[ns]" )
1073
1083
0 commit comments