@@ -747,16 +747,16 @@ def _sub_period_array(self, other):
747
747
new_values [mask ] = NaT
748
748
return new_values
749
749
750
- def _addsub_int_array (
751
- self , other : np .ndarray , op : Callable [[Any , Any ], Any ]
750
+ def _addsub_int_array_or_scalar (
751
+ self , other : np .ndarray | int , op : Callable [[Any , Any ], Any ]
752
752
) -> PeriodArray :
753
753
"""
754
754
Add or subtract array of integers; equivalent to applying
755
755
`_time_shift` pointwise.
756
756
757
757
Parameters
758
758
----------
759
- other : np.ndarray[integer-dtype]
759
+ other : np.ndarray[int64] or int
760
760
op : {operator.add, operator.sub}
761
761
762
762
Returns
@@ -775,12 +775,7 @@ def _add_offset(self, other: BaseOffset):
775
775
assert not isinstance (other , Tick )
776
776
777
777
self ._require_matching_freq (other , base = True )
778
-
779
- # Note: when calling parent class's _add_timedeltalike_scalar,
780
- # it will call delta_to_nanoseconds(delta). Because delta here
781
- # is an integer, delta_to_nanoseconds will return it unchanged.
782
- result = super ()._add_timedeltalike_scalar (other .n )
783
- return type (self )(result , freq = self .freq )
778
+ return self ._addsub_int_array_or_scalar (other .n , operator .add )
784
779
785
780
def _add_timedeltalike_scalar (self , other ):
786
781
"""
@@ -800,10 +795,8 @@ def _add_timedeltalike_scalar(self, other):
800
795
# special handling for np.timedelta64("NaT"), avoid calling
801
796
# _check_timedeltalike_freq_compat as that would raise TypeError
802
797
other = self ._check_timedeltalike_freq_compat (other )
798
+ other = np .timedelta64 (other , "ns" )
803
799
804
- # Note: when calling parent class's _add_timedeltalike_scalar,
805
- # it will call delta_to_nanoseconds(delta). Because delta here
806
- # is an integer, delta_to_nanoseconds will return it unchanged.
807
800
return super ()._add_timedeltalike_scalar (other )
808
801
809
802
def _add_timedelta_arraylike (self , other ):
@@ -828,7 +821,7 @@ def _add_timedelta_arraylike(self, other):
828
821
# all-NaT TimedeltaIndex is equivalent to a single scalar td64 NaT
829
822
return self + np .timedelta64 ("NaT" )
830
823
831
- ordinals = self ._addsub_int_array (delta , operator .add ).asi8
824
+ ordinals = self ._addsub_int_array_or_scalar (delta , operator .add ).asi8
832
825
return type (self )(ordinals , dtype = self .dtype )
833
826
834
827
def _check_timedeltalike_freq_compat (self , other ):
0 commit comments