@@ -54,7 +54,7 @@ cdef const int64_t[::1] _deltas_placeholder = np.array([], dtype=np.int64)
54
54
cdef class Localizer:
55
55
# cdef:
56
56
# tzinfo tz
57
- # NPY_DATETIMEUNIT _reso
57
+ # NPY_DATETIMEUNIT _creso
58
58
# bint use_utc, use_fixed, use_tzlocal, use_dst, use_pytz
59
59
# ndarray trans
60
60
# Py_ssize_t ntrans
@@ -64,9 +64,9 @@ cdef class Localizer:
64
64
65
65
@ cython.initializedcheck (False )
66
66
@ cython.boundscheck (False )
67
- def __cinit__ (self , tzinfo tz , NPY_DATETIMEUNIT reso ):
67
+ def __cinit__ (self , tzinfo tz , NPY_DATETIMEUNIT creso ):
68
68
self .tz = tz
69
- self ._creso = reso
69
+ self ._creso = creso
70
70
self .use_utc = self .use_tzlocal = self .use_fixed = False
71
71
self .use_dst = self .use_pytz = False
72
72
self .ntrans = - 1 # placeholder
@@ -82,22 +82,22 @@ cdef class Localizer:
82
82
83
83
else :
84
84
trans, deltas, typ = get_dst_info(tz)
85
- if reso != NPY_DATETIMEUNIT.NPY_FR_ns:
85
+ if creso != NPY_DATETIMEUNIT.NPY_FR_ns:
86
86
# NB: using floordiv here is implicitly assuming we will
87
87
# never see trans or deltas that are not an integer number
88
88
# of seconds.
89
89
# TODO: avoid these np.array calls
90
- if reso == NPY_DATETIMEUNIT.NPY_FR_us:
90
+ if creso == NPY_DATETIMEUNIT.NPY_FR_us:
91
91
trans = np.array(trans) // 1 _000
92
92
deltas = np.array(deltas) // 1 _000
93
- elif reso == NPY_DATETIMEUNIT.NPY_FR_ms:
93
+ elif creso == NPY_DATETIMEUNIT.NPY_FR_ms:
94
94
trans = np.array(trans) // 1 _000_000
95
95
deltas = np.array(deltas) // 1 _000_000
96
- elif reso == NPY_DATETIMEUNIT.NPY_FR_s:
96
+ elif creso == NPY_DATETIMEUNIT.NPY_FR_s:
97
97
trans = np.array(trans) // 1 _000_000_000
98
98
deltas = np.array(deltas) // 1 _000_000_000
99
99
else :
100
- raise NotImplementedError (reso )
100
+ raise NotImplementedError (creso )
101
101
102
102
self .trans = trans
103
103
self .ntrans = self .trans.shape[0 ]
@@ -121,7 +121,7 @@ cdef class Localizer:
121
121
return utc_val
122
122
elif self .use_tzlocal:
123
123
return utc_val + _tz_localize_using_tzinfo_api(
124
- utc_val, self .tz, to_utc = False , reso = self ._creso, fold = fold
124
+ utc_val, self .tz, to_utc = False , creso = self ._creso, fold = fold
125
125
)
126
126
elif self .use_fixed:
127
127
return utc_val + self .delta
@@ -140,7 +140,7 @@ cdef int64_t tz_localize_to_utc_single(
140
140
tzinfo tz,
141
141
object ambiguous = None ,
142
142
object nonexistent = None ,
143
- NPY_DATETIMEUNIT reso = NPY_DATETIMEUNIT.NPY_FR_ns,
143
+ NPY_DATETIMEUNIT creso = NPY_DATETIMEUNIT.NPY_FR_ns,
144
144
) except ? - 1 :
145
145
""" See tz_localize_to_utc.__doc__"""
146
146
cdef:
@@ -155,18 +155,18 @@ cdef int64_t tz_localize_to_utc_single(
155
155
return val
156
156
157
157
elif is_tzlocal(tz) or is_zoneinfo(tz):
158
- return val - _tz_localize_using_tzinfo_api(val, tz, to_utc = True , reso = reso )
158
+ return val - _tz_localize_using_tzinfo_api(val, tz, to_utc = True , creso = creso )
159
159
160
160
elif is_fixed_offset(tz):
161
161
_, deltas, _ = get_dst_info(tz)
162
162
delta = deltas[0 ]
163
163
# TODO: de-duplicate with Localizer.__init__
164
- if reso != NPY_DATETIMEUNIT.NPY_FR_ns:
165
- if reso == NPY_DATETIMEUNIT.NPY_FR_us:
164
+ if creso != NPY_DATETIMEUNIT.NPY_FR_ns:
165
+ if creso == NPY_DATETIMEUNIT.NPY_FR_us:
166
166
delta = delta // 1000
167
- elif reso == NPY_DATETIMEUNIT.NPY_FR_ms:
167
+ elif creso == NPY_DATETIMEUNIT.NPY_FR_ms:
168
168
delta = delta // 1 _000_000
169
- elif reso == NPY_DATETIMEUNIT.NPY_FR_s:
169
+ elif creso == NPY_DATETIMEUNIT.NPY_FR_s:
170
170
delta = delta // 1 _000_000_000
171
171
172
172
return val - delta
@@ -177,7 +177,7 @@ cdef int64_t tz_localize_to_utc_single(
177
177
tz,
178
178
ambiguous = ambiguous,
179
179
nonexistent = nonexistent,
180
- reso = reso ,
180
+ creso = creso ,
181
181
)[0 ]
182
182
183
183
@@ -188,7 +188,7 @@ def tz_localize_to_utc(
188
188
tzinfo tz ,
189
189
object ambiguous = None ,
190
190
object nonexistent = None ,
191
- NPY_DATETIMEUNIT reso = NPY_DATETIMEUNIT.NPY_FR_ns,
191
+ NPY_DATETIMEUNIT creso = NPY_DATETIMEUNIT.NPY_FR_ns,
192
192
):
193
193
"""
194
194
Localize tzinfo-naive i8 to given time zone (using pytz). If
@@ -216,7 +216,7 @@ def tz_localize_to_utc(
216
216
nonexistent : {None, "NaT", "shift_forward", "shift_backward", "raise", \
217
217
timedelta-like}
218
218
How to handle non-existent times when converting wall times to UTC
219
- reso : NPY_DATETIMEUNIT, default NPY_FR_ns
219
+ creso : NPY_DATETIMEUNIT, default NPY_FR_ns
220
220
221
221
Returns
222
222
-------
@@ -236,8 +236,8 @@ timedelta-like}
236
236
bint shift_forward = False , shift_backward = False
237
237
bint fill_nonexist = False
238
238
str stamp
239
- Localizer info = Localizer(tz, reso = reso )
240
- int64_t pph = periods_per_day(reso ) // 24
239
+ Localizer info = Localizer(tz, creso = creso )
240
+ int64_t pph = periods_per_day(creso ) // 24
241
241
242
242
# Vectorized version of DstTzInfo.localize
243
243
if info.use_utc:
@@ -252,7 +252,7 @@ timedelta-like}
252
252
result[i] = NPY_NAT
253
253
else :
254
254
result[i] = v - _tz_localize_using_tzinfo_api(
255
- v, tz, to_utc = True , reso = reso
255
+ v, tz, to_utc = True , creso = creso
256
256
)
257
257
return result.base # to return underlying ndarray
258
258
@@ -294,7 +294,7 @@ timedelta-like}
294
294
shift_backward = True
295
295
elif PyDelta_Check(nonexistent):
296
296
from .timedeltas import delta_to_nanoseconds
297
- shift_delta = delta_to_nanoseconds(nonexistent, reso = reso )
297
+ shift_delta = delta_to_nanoseconds(nonexistent, reso = creso )
298
298
elif nonexistent not in (' raise' , None ):
299
299
msg = (" nonexistent must be one of {'NaT', 'raise', 'shift_forward', "
300
300
" shift_backwards} or a timedelta object" )
@@ -303,13 +303,13 @@ timedelta-like}
303
303
# Determine whether each date lies left of the DST transition (store in
304
304
# result_a) or right of the DST transition (store in result_b)
305
305
result_a, result_b = _get_utc_bounds(
306
- vals, info.tdata, info.ntrans, info.deltas, reso = reso
306
+ vals, info.tdata, info.ntrans, info.deltas, creso = creso
307
307
)
308
308
309
309
# silence false-positive compiler warning
310
310
dst_hours = np.empty(0 , dtype = np.int64)
311
311
if infer_dst:
312
- dst_hours = _get_dst_hours(vals, result_a, result_b, reso = reso )
312
+ dst_hours = _get_dst_hours(vals, result_a, result_b, creso = creso )
313
313
314
314
# Pre-compute delta_idx_offset that will be used if we go down non-existent
315
315
# paths.
@@ -348,7 +348,7 @@ timedelta-like}
348
348
# TODO: test with non-nano; parametrize test_dt_round_tz_ambiguous
349
349
result[i] = NPY_NAT
350
350
else :
351
- stamp = _render_tstamp(val, reso = reso )
351
+ stamp = _render_tstamp(val, creso = creso )
352
352
raise pytz.AmbiguousTimeError(
353
353
f" Cannot infer dst time from {stamp}, try using the "
354
354
" 'ambiguous' argument"
@@ -386,7 +386,7 @@ timedelta-like}
386
386
elif fill_nonexist:
387
387
result[i] = NPY_NAT
388
388
else :
389
- stamp = _render_tstamp(val, reso = reso )
389
+ stamp = _render_tstamp(val, creso = creso )
390
390
raise pytz.NonExistentTimeError(stamp)
391
391
392
392
return result.base # .base to get underlying ndarray
@@ -422,10 +422,10 @@ cdef inline Py_ssize_t bisect_right_i8(int64_t *data,
422
422
return left
423
423
424
424
425
- cdef inline str _render_tstamp(int64_t val, NPY_DATETIMEUNIT reso ):
425
+ cdef inline str _render_tstamp(int64_t val, NPY_DATETIMEUNIT creso ):
426
426
""" Helper function to render exception messages"""
427
427
from pandas._libs.tslibs.timestamps import Timestamp
428
- ts = Timestamp._from_value_and_reso(val, reso , None )
428
+ ts = Timestamp._from_value_and_reso(val, creso , None )
429
429
return str (ts)
430
430
431
431
@@ -434,7 +434,7 @@ cdef _get_utc_bounds(
434
434
int64_t* tdata,
435
435
Py_ssize_t ntrans,
436
436
const int64_t[::1 ] deltas,
437
- NPY_DATETIMEUNIT reso ,
437
+ NPY_DATETIMEUNIT creso ,
438
438
):
439
439
# Determine whether each date lies left of the DST transition (store in
440
440
# result_a) or right of the DST transition (store in result_b)
@@ -444,7 +444,7 @@ cdef _get_utc_bounds(
444
444
Py_ssize_t i, n = vals.size
445
445
int64_t val, v_left, v_right
446
446
Py_ssize_t isl, isr, pos_left, pos_right
447
- int64_t ppd = periods_per_day(reso )
447
+ int64_t ppd = periods_per_day(creso )
448
448
449
449
result_a = cnp.PyArray_EMPTY(vals.ndim, vals.shape, cnp.NPY_INT64, 0 )
450
450
result_b = cnp.PyArray_EMPTY(vals.ndim, vals.shape, cnp.NPY_INT64, 0 )
@@ -486,11 +486,11 @@ cdef _get_utc_bounds(
486
486
487
487
@ cython.boundscheck (False )
488
488
cdef ndarray[int64_t] _get_dst_hours(
489
- # vals, reso only needed here to potential render an exception message
489
+ # vals, creso only needed here to potential render an exception message
490
490
const int64_t[:] vals,
491
491
ndarray[int64_t] result_a,
492
492
ndarray[int64_t] result_b,
493
- NPY_DATETIMEUNIT reso ,
493
+ NPY_DATETIMEUNIT creso ,
494
494
):
495
495
cdef:
496
496
Py_ssize_t i, n = vals.shape[0 ]
@@ -519,7 +519,7 @@ cdef ndarray[int64_t] _get_dst_hours(
519
519
520
520
if trans_idx.size == 1 :
521
521
# see test_tz_localize_to_utc_ambiguous_infer
522
- stamp = _render_tstamp(vals[trans_idx[0 ]], reso = reso )
522
+ stamp = _render_tstamp(vals[trans_idx[0 ]], creso = creso )
523
523
raise pytz.AmbiguousTimeError(
524
524
f" Cannot infer dst time from {stamp} as there "
525
525
" are no repeated times"
@@ -541,7 +541,7 @@ cdef ndarray[int64_t] _get_dst_hours(
541
541
delta = np.diff(result_a[grp])
542
542
if grp.size == 1 or np.all(delta > 0 ):
543
543
# see test_tz_localize_to_utc_ambiguous_infer
544
- stamp = _render_tstamp(vals[grp[0 ]], reso = reso )
544
+ stamp = _render_tstamp(vals[grp[0 ]], creso = creso )
545
545
raise pytz.AmbiguousTimeError(stamp)
546
546
547
547
# Find the index for the switch and pull from a for dst and b
@@ -567,7 +567,7 @@ cdef ndarray[int64_t] _get_dst_hours(
567
567
# Timezone Conversion
568
568
569
569
cpdef int64_t tz_convert_from_utc_single(
570
- int64_t utc_val, tzinfo tz, NPY_DATETIMEUNIT reso = NPY_DATETIMEUNIT.NPY_FR_ns
570
+ int64_t utc_val, tzinfo tz, NPY_DATETIMEUNIT creso = NPY_DATETIMEUNIT.NPY_FR_ns
571
571
) except ? - 1 :
572
572
"""
573
573
Convert the val (in i8) from UTC to tz
@@ -578,14 +578,14 @@ cpdef int64_t tz_convert_from_utc_single(
578
578
----------
579
579
utc_val : int64
580
580
tz : tzinfo
581
- reso : NPY_DATETIMEUNIT, default NPY_FR_ns
581
+ creso : NPY_DATETIMEUNIT, default NPY_FR_ns
582
582
583
583
Returns
584
584
-------
585
585
converted: int64
586
586
"""
587
587
cdef:
588
- Localizer info = Localizer(tz, reso = reso )
588
+ Localizer info = Localizer(tz, creso = creso )
589
589
Py_ssize_t pos
590
590
591
591
# Note: caller is responsible for ensuring utc_val != NPY_NAT
@@ -598,7 +598,7 @@ cdef int64_t _tz_localize_using_tzinfo_api(
598
598
int64_t val,
599
599
tzinfo tz,
600
600
bint to_utc = True ,
601
- NPY_DATETIMEUNIT reso = NPY_DATETIMEUNIT.NPY_FR_ns,
601
+ NPY_DATETIMEUNIT creso = NPY_DATETIMEUNIT.NPY_FR_ns,
602
602
bint* fold = NULL ,
603
603
) except ? - 1 :
604
604
"""
@@ -613,7 +613,7 @@ cdef int64_t _tz_localize_using_tzinfo_api(
613
613
tz : tzinfo
614
614
to_utc : bint
615
615
True if converting _to_ UTC, False if going the other direction.
616
- reso : NPY_DATETIMEUNIT
616
+ creso : NPY_DATETIMEUNIT
617
617
fold : bint*, default NULL
618
618
pointer to fold: whether datetime ends up in a fold or not
619
619
after adjustment.
@@ -633,9 +633,9 @@ cdef int64_t _tz_localize_using_tzinfo_api(
633
633
datetime dt
634
634
int64_t delta
635
635
timedelta td
636
- int64_t pps = periods_per_second(reso )
636
+ int64_t pps = periods_per_second(creso )
637
637
638
- pandas_datetime_to_datetimestruct(val, reso , & dts)
638
+ pandas_datetime_to_datetimestruct(val, creso , & dts)
639
639
640
640
# datetime_new is cython-optimized constructor
641
641
if not to_utc:
0 commit comments