@@ -3,11 +3,13 @@ import warnings
3
3
from cpython.datetime cimport (
4
4
PyDate_Check,
5
5
PyDateTime_Check,
6
- PyDateTime_IMPORT,
7
6
PyDelta_Check,
8
7
datetime,
8
+ import_datetime,
9
9
timedelta,
10
10
)
11
+
12
+ import_datetime()
11
13
from cpython.object cimport (
12
14
Py_EQ,
13
15
Py_GE,
@@ -18,10 +20,6 @@ from cpython.object cimport (
18
20
PyObject_RichCompare,
19
21
)
20
22
21
- PyDateTime_IMPORT
22
-
23
- from cpython.version cimport PY_MINOR_VERSION
24
-
25
23
import numpy as np
26
24
27
25
cimport numpy as cnp
@@ -43,14 +41,6 @@ cdef set c_nat_strings = nat_strings
43
41
cdef int64_t NPY_NAT = util.get_nat()
44
42
iNaT = NPY_NAT # python-visible constant
45
43
46
- cdef bint _nat_scalar_rules[6 ]
47
- _nat_scalar_rules[Py_EQ] = False
48
- _nat_scalar_rules[Py_NE] = True
49
- _nat_scalar_rules[Py_LT] = False
50
- _nat_scalar_rules[Py_LE] = False
51
- _nat_scalar_rules[Py_GT] = False
52
- _nat_scalar_rules[Py_GE] = False
53
-
54
44
# ----------------------------------------------------------------------
55
45
56
46
@@ -107,24 +97,23 @@ def __nat_unpickle(*args):
107
97
cdef class _NaT(datetime):
108
98
# cdef readonly:
109
99
# int64_t value
110
- # object freq
111
100
112
101
# higher than np.ndarray and np.matrix
113
102
__array_priority__ = 100
114
103
115
104
def __richcmp__ (_NaT self , object other , int op ):
116
105
if util.is_datetime64_object(other) or PyDateTime_Check(other):
117
106
# We treat NaT as datetime-like for this comparison
118
- return _nat_scalar_rules[op]
107
+ return op == Py_NE
119
108
120
109
elif util.is_timedelta64_object(other) or PyDelta_Check(other):
121
110
# We treat NaT as timedelta-like for this comparison
122
- return _nat_scalar_rules[op]
111
+ return op == Py_NE
123
112
124
113
elif util.is_array(other):
125
114
if other.dtype.kind in " mM" :
126
115
result = np.empty(other.shape, dtype = np.bool_)
127
- result.fill(_nat_scalar_rules[op] )
116
+ result.fill(op == Py_NE )
128
117
elif other.dtype.kind == " O" :
129
118
result = np.array([PyObject_RichCompare(self , x, op) for x in other])
130
119
elif op == Py_EQ:
@@ -510,8 +499,7 @@ class NaTType(_NaT):
510
499
utcoffset = _make_error_func(" utcoffset" , datetime)
511
500
512
501
# "fromisocalendar" was introduced in 3.8
513
- if PY_MINOR_VERSION >= 8 :
514
- fromisocalendar = _make_error_func(" fromisocalendar" , datetime)
502
+ fromisocalendar = _make_error_func(" fromisocalendar" , datetime)
515
503
516
504
# ----------------------------------------------------------------------
517
505
# The remaining methods have docstrings copy/pasted from the analogous
0 commit comments