@@ -1105,8 +1105,12 @@ def _add_datetimelike_scalar(self, other):
1105
1105
return DatetimeArray (result )
1106
1106
1107
1107
i8 = self .asi8
1108
- result = checked_add_with_arr (i8 , other .value , arr_mask = self ._isnan )
1109
- result = self ._maybe_mask_results (result )
1108
+ # Incompatible types in assignment (expression has type "ndarray[Any,
1109
+ # dtype[signedinteger[_64Bit]]]", variable has type
1110
+ # "ndarray[Any, dtype[datetime64]]")
1111
+ result = checked_add_with_arr ( # type: ignore[assignment]
1112
+ i8 , other .value , arr_mask = self ._isnan
1113
+ )
1110
1114
dtype = DatetimeTZDtype (tz = other .tz ) if other .tz else DT64NS_DTYPE
1111
1115
return DatetimeArray (result , dtype = dtype , freq = self .freq )
1112
1116
@@ -1147,7 +1151,6 @@ def _sub_datetimelike_scalar(self, other: datetime | np.datetime64):
1147
1151
1148
1152
i8 = self .asi8
1149
1153
result = checked_add_with_arr (i8 , - other .value , arr_mask = self ._isnan )
1150
- result = self ._maybe_mask_results (result )
1151
1154
return result .view ("timedelta64[ns]" )
1152
1155
1153
1156
@final
@@ -1169,31 +1172,30 @@ def _sub_datetime_arraylike(self, other):
1169
1172
1170
1173
self_i8 = self .asi8
1171
1174
other_i8 = other .asi8
1172
- arr_mask = self ._isnan | other ._isnan
1173
- new_values = checked_add_with_arr (self_i8 , - other_i8 , arr_mask = arr_mask )
1174
- if self ._hasna or other ._hasna :
1175
- np .putmask (new_values , arr_mask , iNaT )
1175
+ new_values = checked_add_with_arr (
1176
+ self_i8 , - other_i8 , arr_mask = self ._isnan , b_mask = other ._isnan
1177
+ )
1176
1178
return new_values .view ("timedelta64[ns]" )
1177
1179
1178
1180
@final
1179
- def _sub_period (self , other : Period ):
1181
+ def _sub_period (self , other : Period ) -> npt . NDArray [ np . object_ ] :
1180
1182
if not is_period_dtype (self .dtype ):
1181
1183
raise TypeError (f"cannot subtract Period from a { type (self ).__name__ } " )
1182
1184
1183
1185
# If the operation is well-defined, we return an object-dtype ndarray
1184
1186
# of DateOffsets. Null entries are filled with pd.NaT
1185
1187
self ._check_compatible_with (other )
1186
1188
asi8 = self .asi8
1187
- new_data = asi8 - other .ordinal
1188
- new_data = np .array ([self .freq .base * x for x in new_data ])
1189
+ new_i8_data = asi8 - other .ordinal # TODO: checked_add_with_arr
1190
+ new_data = np .array ([self .freq .base * x for x in new_i8_data ])
1189
1191
1190
1192
if self ._hasna :
1191
1193
new_data [self ._isnan ] = NaT
1192
1194
1193
1195
return new_data
1194
1196
1195
1197
@final
1196
- def _add_period (self , other : Period ):
1198
+ def _add_period (self , other : Period ) -> PeriodArray :
1197
1199
if not is_timedelta64_dtype (self .dtype ):
1198
1200
raise TypeError (f"cannot add Period to a { type (self ).__name__ } " )
1199
1201
@@ -1226,8 +1228,6 @@ def _add_timedeltalike_scalar(self, other):
1226
1228
inc = delta_to_nanoseconds (other , reso = self ._reso ) # type: ignore[attr-defined]
1227
1229
1228
1230
new_values = checked_add_with_arr (self .asi8 , inc , arr_mask = self ._isnan )
1229
- new_values = new_values .view ("i8" )
1230
- new_values = self ._maybe_mask_results (new_values )
1231
1231
new_values = new_values .view (self ._ndarray .dtype )
1232
1232
1233
1233
new_freq = None
@@ -1263,10 +1263,6 @@ def _add_timedelta_arraylike(
1263
1263
new_values = checked_add_with_arr (
1264
1264
self_i8 , other_i8 , arr_mask = self ._isnan , b_mask = other ._isnan
1265
1265
)
1266
- if self ._hasna or other ._hasna :
1267
- mask = self ._isnan | other ._isnan
1268
- np .putmask (new_values , mask , iNaT )
1269
-
1270
1266
return type (self )(new_values , dtype = self .dtype )
1271
1267
1272
1268
@final
@@ -1310,11 +1306,11 @@ def _sub_period_array(self, other: PeriodArray) -> npt.NDArray[np.object_]:
1310
1306
self = cast ("PeriodArray" , self )
1311
1307
self ._require_matching_freq (other )
1312
1308
1313
- new_values = checked_add_with_arr (
1309
+ new_i8_values = checked_add_with_arr (
1314
1310
self .asi8 , - other .asi8 , arr_mask = self ._isnan , b_mask = other ._isnan
1315
1311
)
1316
1312
1317
- new_values = np .array ([self .freq .base * x for x in new_values ])
1313
+ new_values = np .array ([self .freq .base * x for x in new_i8_values ])
1318
1314
if self ._hasna or other ._hasna :
1319
1315
mask = self ._isnan | other ._isnan
1320
1316
new_values [mask ] = NaT
0 commit comments