@@ -37,8 +37,6 @@ cdef extern from "src/datetime/np_datetime.h":
37
37
38
38
cimport pandas._libs.tslibs.util as util
39
39
40
- from pandas._libs.tslibs.base cimport ABCPeriod, is_period_object
41
-
42
40
from pandas._libs.tslibs.timestamps import Timestamp
43
41
from pandas._libs.tslibs.timezones cimport is_utc, is_tzlocal, get_dst_info
44
42
from pandas._libs.tslibs.timedeltas import Timedelta
@@ -1533,7 +1531,7 @@ class IncompatibleFrequency(ValueError):
1533
1531
pass
1534
1532
1535
1533
1536
- cdef class _Period(ABCPeriod) :
1534
+ cdef class _Period:
1537
1535
1538
1536
cdef readonly:
1539
1537
int64_t ordinal
@@ -1657,8 +1655,11 @@ cdef class _Period(ABCPeriod):
1657
1655
raise IncompatibleFrequency(msg)
1658
1656
# GH 23915 - mul by base freq since __add__ is agnostic of n
1659
1657
return (self .ordinal - other.ordinal) * self .freq.base
1658
+ elif other is NaT:
1659
+ return NaT
1660
1660
return NotImplemented
1661
1661
elif is_period_object(other):
1662
+ # this can be reached via __rsub__ because of cython rules
1662
1663
if self is NaT:
1663
1664
return NaT
1664
1665
return NotImplemented
@@ -2463,6 +2464,10 @@ class Period(_Period):
2463
2464
return cls ._from_ordinal(ordinal, freq)
2464
2465
2465
2466
2467
+ cdef bint is_period_object(object obj):
2468
+ return isinstance (obj, _Period)
2469
+
2470
+
2466
2471
cdef int64_t _ordinal_from_fields(int year, int month, quarter, int day,
2467
2472
int hour, int minute, int second, freq):
2468
2473
base, mult = get_freq_code(freq)
0 commit comments