@@ -47,7 +47,7 @@ def _make_nan_func(func_name, doc):
47
47
48
48
def _make_nat_func (func_name , doc ):
49
49
def f (*args , **kwargs ):
50
- return NaT
50
+ return c_NaT
51
51
f.__name__ = func_name
52
52
f.__doc__ = doc
53
53
return f
@@ -67,10 +67,10 @@ def _make_error_func(func_name, cls):
67
67
68
68
69
69
cdef _nat_divide_op(self , other):
70
- if PyDelta_Check(other) or is_timedelta64_object(other) or other is NaT :
70
+ if PyDelta_Check(other) or is_timedelta64_object(other) or other is c_NaT :
71
71
return np.nan
72
72
if is_integer_object(other) or is_float_object(other):
73
- return NaT
73
+ return c_NaT
74
74
return NotImplemented
75
75
76
76
@@ -82,15 +82,15 @@ cdef _nat_rdivide_op(self, other):
82
82
83
83
def __nat_unpickle (*args ):
84
84
# return constant defined in the module
85
- return NaT
85
+ return c_NaT
86
86
87
87
# ----------------------------------------------------------------------
88
88
89
89
90
90
cdef class _NaT(datetime):
91
- cdef readonly:
92
- int64_t value
93
- object freq
91
+ # cdef readonly:
92
+ # int64_t value
93
+ # object freq
94
94
95
95
def __hash__ (_NaT self ):
96
96
# py3k needs this defined here
@@ -116,18 +116,18 @@ cdef class _NaT(datetime):
116
116
117
117
def __add__ (self , other ):
118
118
if PyDateTime_Check(other):
119
- return NaT
119
+ return c_NaT
120
120
121
121
elif hasattr (other, ' delta' ):
122
122
# Timedelta, offsets.Tick, offsets.Week
123
- return NaT
123
+ return c_NaT
124
124
elif getattr (other, ' _typ' , None ) in [' dateoffset' , ' series' ,
125
125
' period' , ' datetimeindex' ,
126
126
' timedeltaindex' ]:
127
127
# Duplicate logic in _Timestamp.__add__ to avoid needing
128
128
# to subclass; allows us to @final(_Timestamp.__add__)
129
129
return NotImplemented
130
- return NaT
130
+ return c_NaT
131
131
132
132
def __sub__ (self , other ):
133
133
# Duplicate some logic from _Timestamp.__sub__ to avoid needing
@@ -184,19 +184,6 @@ cdef class _NaT(datetime):
184
184
""" Returns a numpy.datetime64 object with 'ns' precision """
185
185
return np.datetime64(' NaT' , ' ns' )
186
186
187
-
188
- class NaTType (_NaT ):
189
- """ (N)ot-(A)-(T)ime, the time equivalent of NaN"""
190
-
191
- def __new__ (cls ):
192
- cdef _NaT base
193
-
194
- base = _NaT.__new__ (cls , 1 , 1 , 1 )
195
- base.value = NPY_NAT
196
- base.freq = None
197
-
198
- return base
199
-
200
187
def __repr__ (self ):
201
188
return ' NaT'
202
189
@@ -216,20 +203,11 @@ class NaTType(_NaT):
216
203
def __long__ (self ):
217
204
return NPY_NAT
218
205
219
- def __reduce_ex__ (self , protocol ):
220
- # python 3.6 compat
221
- # http://bugs.python.org/issue28730
222
- # now __reduce_ex__ is defined and higher priority than __reduce__
223
- return self .__reduce__()
224
-
225
- def __reduce__ (self ):
226
- return (__nat_unpickle, (None , ))
227
-
228
206
def total_seconds (self ):
229
207
"""
230
208
Total duration of timedelta in seconds (to ns precision)
231
209
"""
232
- # GH 10939
210
+ # GH# 10939
233
211
return np.nan
234
212
235
213
@property
@@ -260,6 +238,28 @@ class NaTType(_NaT):
260
238
def is_year_end (self ):
261
239
return False
262
240
241
+
242
+ class NaTType (_NaT ):
243
+ """ (N)ot-(A)-(T)ime, the time equivalent of NaN"""
244
+
245
+ def __new__ (cls ):
246
+ cdef _NaT base
247
+
248
+ base = _NaT.__new__ (cls , 1 , 1 , 1 )
249
+ base.value = NPY_NAT
250
+ base.freq = None
251
+
252
+ return base
253
+
254
+ def __reduce_ex__ (self , protocol ):
255
+ # python 3.6 compat
256
+ # http://bugs.python.org/issue28730
257
+ # now __reduce_ex__ is defined and higher priority than __reduce__
258
+ return self .__reduce__()
259
+
260
+ def __reduce__ (self ):
261
+ return (__nat_unpickle, (None , ))
262
+
263
263
def __rdiv__ (self , other ):
264
264
return _nat_rdivide_op(self , other)
265
265
@@ -271,7 +271,7 @@ class NaTType(_NaT):
271
271
272
272
def __rmul__ (self , other ):
273
273
if is_integer_object(other) or is_float_object(other):
274
- return NaT
274
+ return c_NaT
275
275
return NotImplemented
276
276
277
277
# ----------------------------------------------------------------------
@@ -659,14 +659,15 @@ class NaTType(_NaT):
659
659
""" )
660
660
661
661
662
- NaT = NaTType()
662
+ c_NaT = NaTType() # C-visible
663
+ NaT = c_NaT # Python-visible
663
664
664
665
665
666
# ----------------------------------------------------------------------
666
667
667
668
cdef inline bint checknull_with_nat(object val):
668
669
""" utility to check if a value is a nat or not """
669
- return val is None or util.is_nan(val) or val is NaT
670
+ return val is None or util.is_nan(val) or val is c_NaT
670
671
671
672
672
673
cdef inline bint is_null_datetimelike(object val):
@@ -683,7 +684,7 @@ cdef inline bint is_null_datetimelike(object val):
683
684
"""
684
685
if val is None or util.is_nan(val):
685
686
return True
686
- elif val is NaT :
687
+ elif val is c_NaT :
687
688
return True
688
689
elif util.is_timedelta64_object(val):
689
690
return val.view(' int64' ) == NPY_NAT
0 commit comments