|
5 | 5 |
|
6 | 6 | import numpy as np
|
7 | 7 |
|
8 |
| -from pandas._libs import NaT, NaTType, Timestamp, algos, iNaT, lib |
9 |
| -from pandas._libs.tslibs.period import DIFFERENT_FREQ, IncompatibleFrequency, Period |
| 8 | +from pandas._libs import NaT, NaTType, Period, Timestamp, algos, iNaT, lib |
10 | 9 | from pandas._libs.tslibs.timedeltas import delta_to_nanoseconds
|
11 | 10 | from pandas._libs.tslibs.timestamps import (
|
12 | 11 | RoundTo,
|
@@ -739,7 +738,7 @@ def _validate_shift_value(self, fill_value):
|
739 | 738 | # only warn if we're not going to raise
|
740 | 739 | if self._scalar_type is Period and lib.is_integer(fill_value):
|
741 | 740 | # kludge for #31971 since Period(integer) tries to cast to str
|
742 |
| - new_fill = Period._from_ordinal(fill_value, freq=self.freq) |
| 741 | + new_fill = Period._from_ordinal(fill_value, freq=self.dtype.freq) |
743 | 742 | else:
|
744 | 743 | new_fill = self._scalar_type(fill_value)
|
745 | 744 |
|
@@ -1095,7 +1094,7 @@ def _resolution(self):
|
1095 | 1094 | return frequencies.Resolution.get_reso_from_freq(self.freqstr)
|
1096 | 1095 |
|
1097 | 1096 | @property # NB: override with cache_readonly in immutable subclasses
|
1098 |
| - def resolution(self): |
| 1097 | + def resolution(self) -> str: |
1099 | 1098 | """
|
1100 | 1099 | Returns day, hour, minute, second, millisecond or microsecond
|
1101 | 1100 | """
|
@@ -1278,41 +1277,11 @@ def _sub_nat(self):
|
1278 | 1277 | return result.view("timedelta64[ns]")
|
1279 | 1278 |
|
1280 | 1279 | def _sub_period_array(self, other):
|
1281 |
| - """ |
1282 |
| - Subtract a Period Array/Index from self. This is only valid if self |
1283 |
| - is itself a Period Array/Index, raises otherwise. Both objects must |
1284 |
| - have the same frequency. |
1285 |
| -
|
1286 |
| - Parameters |
1287 |
| - ---------- |
1288 |
| - other : PeriodIndex or PeriodArray |
1289 |
| -
|
1290 |
| - Returns |
1291 |
| - ------- |
1292 |
| - result : np.ndarray[object] |
1293 |
| - Array of DateOffset objects; nulls represented by NaT. |
1294 |
| - """ |
1295 |
| - if not is_period_dtype(self.dtype): |
1296 |
| - raise TypeError( |
1297 |
| - f"cannot subtract {other.dtype}-dtype from {type(self).__name__}" |
1298 |
| - ) |
1299 |
| - |
1300 |
| - if self.freq != other.freq: |
1301 |
| - msg = DIFFERENT_FREQ.format( |
1302 |
| - cls=type(self).__name__, own_freq=self.freqstr, other_freq=other.freqstr |
1303 |
| - ) |
1304 |
| - raise IncompatibleFrequency(msg) |
1305 |
| - |
1306 |
| - new_values = checked_add_with_arr( |
1307 |
| - self.asi8, -other.asi8, arr_mask=self._isnan, b_mask=other._isnan |
| 1280 | + # Overridden by PeriodArray |
| 1281 | + raise TypeError( |
| 1282 | + f"cannot subtract {other.dtype}-dtype from {type(self).__name__}" |
1308 | 1283 | )
|
1309 | 1284 |
|
1310 |
| - new_values = np.array([self.freq.base * x for x in new_values]) |
1311 |
| - if self._hasnans or other._hasnans: |
1312 |
| - mask = (self._isnan) | (other._isnan) |
1313 |
| - new_values[mask] = NaT |
1314 |
| - return new_values |
1315 |
| - |
1316 | 1285 | def _addsub_object_array(self, other: np.ndarray, op):
|
1317 | 1286 | """
|
1318 | 1287 | Add or subtract array-like of DateOffset objects
|
|
0 commit comments