@@ -112,8 +112,11 @@ def __init__(self, data, dtype=None, freq=None, copy=False):
112112
113113 @classmethod
114114 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 :
117120 raise AbstractMethodError (cls )
118121
119122 @property
@@ -217,7 +220,7 @@ def _box_func(self, x):
217220 """
218221 raise AbstractMethodError (self )
219222
220- def _box_values (self , values ):
223+ def _box_values (self , values ) -> np . ndarray :
221224 """
222225 apply box func to passed values
223226 """
@@ -416,7 +419,9 @@ def _values_for_factorize(self):
416419 return self ._ndarray , iNaT
417420
418421 @classmethod
419- def _from_factorized (cls , values , original ):
422+ def _from_factorized (
423+ cls : Type [DatetimeLikeArrayT ], values , original
424+ ) -> DatetimeLikeArrayT :
420425 return cls (values , dtype = original .dtype )
421426
422427 # ------------------------------------------------------------------
@@ -661,7 +666,7 @@ def _unbox(
661666 # These are not part of the EA API, but we implement them because
662667 # pandas assumes they're there.
663668
664- def value_counts (self , dropna = False ):
669+ def value_counts (self , dropna : bool = False ):
665670 """
666671 Return a Series containing counts of unique values.
667672
@@ -755,28 +760,30 @@ def isin(self, values) -> np.ndarray:
755760 # ------------------------------------------------------------------
756761 # Null Handling
757762
758- def isna (self ):
763+ def isna (self ) -> np . ndarray :
759764 return self ._isnan
760765
761766 @property # NB: override with cache_readonly in immutable subclasses
762- def _isnan (self ):
767+ def _isnan (self ) -> np . ndarray :
763768 """
764769 return if each value is nan
765770 """
766771 return self .asi8 == iNaT
767772
768773 @property # NB: override with cache_readonly in immutable subclasses
769- def _hasnans (self ):
774+ def _hasnans (self ) -> np . ndarray :
770775 """
771776 return if I have any nans; enables various perf speedups
772777 """
773778 return bool (self ._isnan .any ())
774779
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 :
776783 """
777784 Parameters
778785 ----------
779- result : a ndarray
786+ result : np. ndarray
780787 fill_value : object, default iNaT
781788 convert : str, dtype or None
782789
@@ -794,7 +801,7 @@ def _maybe_mask_results(self, result, fill_value=iNaT, convert=None):
794801 result = result .astype (convert )
795802 if fill_value is None :
796803 fill_value = np .nan
797- result [ self ._isnan ] = fill_value
804+ np . putmask ( result , self ._isnan , fill_value )
798805 return result
799806
800807 # ------------------------------------------------------------------
@@ -893,22 +900,24 @@ def _validate_frequency(cls, index, freq, **kwargs):
893900 ) from e
894901
895902 @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 :
897906 raise AbstractMethodError (cls )
898907
899908 # monotonicity/uniqueness properties are called via frequencies.infer_freq,
900909 # see GH#23789
901910
902911 @property
903- def _is_monotonic_increasing (self ):
912+ def _is_monotonic_increasing (self ) -> bool :
904913 return algos .is_monotonic (self .asi8 , timelike = True )[0 ]
905914
906915 @property
907- def _is_monotonic_decreasing (self ):
916+ def _is_monotonic_decreasing (self ) -> bool :
908917 return algos .is_monotonic (self .asi8 , timelike = True )[1 ]
909918
910919 @property
911- def _is_unique (self ):
920+ def _is_unique (self ) -> bool :
912921 return len (unique1d (self .asi8 )) == len (self )
913922
914923 # ------------------------------------------------------------------
@@ -940,9 +949,10 @@ def _cmp_method(self, other, op):
940949 result = op (self ._ndarray .view ("i8" ), other_vals .view ("i8" ))
941950
942951 o_mask = isna (other )
943- if self ._hasnans | np .any (o_mask ):
952+ mask = self ._isnan | o_mask
953+ if mask .any ():
944954 nat_result = op is operator .ne
945- result [ self . _isnan | o_mask ] = nat_result
955+ np . putmask ( result , mask , nat_result )
946956
947957 return result
948958
@@ -996,7 +1006,7 @@ def _add_timedeltalike_scalar(self, other):
9961006 if isna (other ):
9971007 # i.e np.timedelta64("NaT"), not recognized by delta_to_nanoseconds
9981008 new_values = np .empty (self .shape , dtype = "i8" )
999- new_values [:] = iNaT
1009+ new_values . fill ( iNaT )
10001010 return type (self )(new_values , dtype = self .dtype )
10011011
10021012 inc = delta_to_nanoseconds (other )
@@ -1038,7 +1048,7 @@ def _add_timedelta_arraylike(self, other):
10381048 )
10391049 if self ._hasnans or other ._hasnans :
10401050 mask = self ._isnan | other ._isnan
1041- new_values [ mask ] = iNaT
1051+ np . putmask ( new_values , mask , iNaT )
10421052
10431053 return type (self )(new_values , dtype = self .dtype )
10441054
@@ -1053,7 +1063,7 @@ def _add_nat(self):
10531063
10541064 # GH#19124 pd.NaT is treated like a timedelta for both timedelta
10551065 # and datetime dtypes
1056- result = np .zeros (self .shape , dtype = np .int64 )
1066+ result = np .empty (self .shape , dtype = np .int64 )
10571067 result .fill (iNaT )
10581068 return type (self )(result , dtype = self .dtype , freq = None )
10591069
@@ -1067,7 +1077,7 @@ def _sub_nat(self):
10671077 # For datetime64 dtypes by convention we treat NaT as a datetime, so
10681078 # this subtraction returns a timedelta64 dtype.
10691079 # 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 )
10711081 result .fill (iNaT )
10721082 return result .view ("timedelta64[ns]" )
10731083
0 commit comments