1
1
# -*- coding: utf-8 -*-
2
+ # cython: boundscheck=False, wraparound=False
2
3
from datetime import datetime, date
3
4
4
5
from cpython cimport (
@@ -46,7 +47,7 @@ from frequencies cimport (get_freq_code, get_base_alias,
46
47
get_rule_month)
47
48
from parsing import parse_time_string
48
49
from resolution import Resolution
49
- from nattype import nat_strings, NaT, iNaT
50
+ from nattype import nat_strings, NaT
50
51
from nattype cimport _nat_scalar_rules, NPY_NAT, is_null_datetimelike
51
52
from offsets cimport to_offset
52
53
from offsets import _Tick
@@ -976,8 +977,6 @@ cdef inline int month_to_quarter(int month):
976
977
# Period logic
977
978
978
979
979
- @ cython.wraparound (False )
980
- @ cython.boundscheck (False )
981
980
def dt64arr_to_periodarr (int64_t[:] dtarr , int freq , tz = None ):
982
981
"""
983
982
Convert array of datetime64 values (passed in as 'i8' dtype) to a set of
@@ -1005,8 +1004,6 @@ def dt64arr_to_periodarr(int64_t[:] dtarr, int freq, tz=None):
1005
1004
return out.base # .base to access underlying np.ndarray
1006
1005
1007
1006
1008
- @ cython.wraparound (False )
1009
- @ cython.boundscheck (False )
1010
1007
def periodarr_to_dt64arr (int64_t[:] periodarr , int freq ):
1011
1008
"""
1012
1009
Convert array to datetime64 values from a set of ordinals corresponding to
@@ -1040,8 +1037,8 @@ cpdef int64_t period_asfreq(int64_t ordinal, int freq1, int freq2, bint end):
1040
1037
freq_conv_func func
1041
1038
asfreq_info af_info
1042
1039
1043
- if ordinal == iNaT :
1044
- return iNaT
1040
+ if ordinal == NPY_NAT :
1041
+ return NPY_NAT
1045
1042
1046
1043
func = get_asfreq_func(freq1, freq2)
1047
1044
get_asfreq_info(freq1, freq2, end, & af_info)
@@ -1125,7 +1122,7 @@ def period_asfreq_arr(int64_t[:] arr, int freq1, int freq2, bint end):
1125
1122
1126
1123
for i in range (n):
1127
1124
val = arr[i]
1128
- if val != iNaT :
1125
+ if val != NPY_NAT :
1129
1126
val = func(val, & af_info)
1130
1127
if val == INT32_MIN:
1131
1128
raise ValueError (" Unable to convert to desired frequency." )
@@ -1183,7 +1180,7 @@ def period_format(int64_t value, int freq, object fmt=None):
1183
1180
cdef:
1184
1181
int freq_group
1185
1182
1186
- if value == iNaT :
1183
+ if value == NPY_NAT :
1187
1184
return repr (NaT)
1188
1185
1189
1186
if fmt is None :
@@ -1239,6 +1236,7 @@ cdef object _period_strftime(int64_t value, int freq, object fmt):
1239
1236
list found_pat = [False ] * len (extra_fmts)
1240
1237
int year, quarter
1241
1238
1239
+
1242
1240
if isinstance (fmt, unicode ):
1243
1241
fmt = fmt.encode(' utf-8' )
1244
1242
@@ -1386,7 +1384,7 @@ def get_period_field_arr(int code, int64_t[:] arr, int freq):
1386
1384
out = np.empty(sz, dtype = np.int64)
1387
1385
1388
1386
for i in range (sz):
1389
- if arr[i] == iNaT :
1387
+ if arr[i] == NPY_NAT :
1390
1388
out[i] = - 1
1391
1389
continue
1392
1390
out[i] = func(arr[i], freq)
@@ -1434,7 +1432,7 @@ def extract_ordinals(object[:] values, freq):
1434
1432
p = values[i]
1435
1433
1436
1434
if is_null_datetimelike(p):
1437
- ordinals[i] = iNaT
1435
+ ordinals[i] = NPY_NAT
1438
1436
else :
1439
1437
try :
1440
1438
ordinals[i] = p.ordinal
@@ -1447,7 +1445,7 @@ def extract_ordinals(object[:] values, freq):
1447
1445
p = Period(p, freq = freq)
1448
1446
if p is NaT:
1449
1447
# input may contain NaT-like string
1450
- ordinals[i] = iNaT
1448
+ ordinals[i] = NPY_NAT
1451
1449
else :
1452
1450
ordinals[i] = p.ordinal
1453
1451
@@ -1475,8 +1473,6 @@ def extract_freq(object[:] values):
1475
1473
# -----------------------------------------------------------------------
1476
1474
# period helpers
1477
1475
1478
- @ cython.wraparound (False )
1479
- @ cython.boundscheck (False )
1480
1476
cdef int64_t[:] localize_dt64arr_to_period(int64_t[:] stamps,
1481
1477
int freq, object tz):
1482
1478
cdef:
@@ -1572,7 +1568,7 @@ cdef class _Period(object):
1572
1568
"""
1573
1569
Fast creation from an ordinal and freq that are already validated!
1574
1570
"""
1575
- if ordinal == iNaT :
1571
+ if ordinal == NPY_NAT :
1576
1572
return NaT
1577
1573
else :
1578
1574
freq = cls ._maybe_convert_freq(freq)
@@ -2406,7 +2402,7 @@ class Period(_Period):
2406
2402
if (year is None and month is None and
2407
2403
quarter is None and day is None and
2408
2404
hour is None and minute is None and second is None ):
2409
- ordinal = iNaT
2405
+ ordinal = NPY_NAT
2410
2406
else :
2411
2407
if freq is None :
2412
2408
raise ValueError (" If value is None, freq cannot be None" )
@@ -2432,15 +2428,15 @@ class Period(_Period):
2432
2428
ordinal = converted.ordinal
2433
2429
2434
2430
elif is_null_datetimelike(value) or value in nat_strings:
2435
- ordinal = iNaT
2431
+ ordinal = NPY_NAT
2436
2432
2437
2433
elif is_string_object(value) or util.is_integer_object(value):
2438
2434
if util.is_integer_object(value):
2439
2435
value = str (value)
2440
2436
value = value.upper()
2441
2437
dt, _, reso = parse_time_string(value, freq)
2442
2438
if dt is NaT:
2443
- ordinal = iNaT
2439
+ ordinal = NPY_NAT
2444
2440
2445
2441
if freq is None :
2446
2442
try :
0 commit comments