@@ -183,29 +183,28 @@ timedelta-like}
183
183
localized : ndarray[int64_t]
184
184
"""
185
185
cdef:
186
- const int64_t[::1 ] deltas
187
186
ndarray[uint8_t, cast= True ] ambiguous_array
188
- Py_ssize_t i, idx, pos, ntrans, n = vals.shape[0 ]
187
+ Py_ssize_t i, idx, pos, n = vals.shape[0 ]
189
188
Py_ssize_t delta_idx_offset, delta_idx, pos_left, pos_right
190
- int64_t * tdata
191
189
int64_t v, left, right, val, new_local, remaining_mins
192
190
int64_t first_delta, delta
193
191
int64_t shift_delta = 0
194
- ndarray[int64_t] trans, result_a, result_b, dst_hours
192
+ ndarray[int64_t] result_a, result_b, dst_hours
195
193
int64_t[::1 ] result
196
194
npy_datetimestruct dts
197
195
bint infer_dst = False , is_dst = False , fill = False
198
196
bint shift_forward = False , shift_backward = False
199
197
bint fill_nonexist = False
200
198
str stamp
199
+ Localizer info = Localizer(tz)
201
200
202
201
# Vectorized version of DstTzInfo.localize
203
- if is_utc(tz) or tz is None :
202
+ if info.use_utc :
204
203
return vals.copy()
205
204
206
205
result = cnp.PyArray_EMPTY(vals.ndim, vals.shape, cnp.NPY_INT64, 0 )
207
206
208
- if is_tzlocal(tz) or is_zoneinfo(tz) :
207
+ if info.use_tzlocal :
209
208
for i in range (n):
210
209
v = vals[i]
211
210
if v == NPY_NAT:
@@ -214,9 +213,8 @@ timedelta-like}
214
213
result[i] = v - _tz_localize_using_tzinfo_api(v, tz, to_utc = True )
215
214
return result.base # to return underlying ndarray
216
215
217
- elif is_fixed_offset(tz):
218
- _, deltas, _ = get_dst_info(tz)
219
- delta = deltas[0 ]
216
+ elif info.use_fixed:
217
+ delta = info.delta
220
218
for i in range (n):
221
219
v = vals[i]
222
220
if v == NPY_NAT:
@@ -259,14 +257,9 @@ timedelta-like}
259
257
" shift_backwards} or a timedelta object" )
260
258
raise ValueError (msg)
261
259
262
- trans, deltas, _ = get_dst_info(tz)
263
-
264
- tdata = < int64_t* > cnp.PyArray_DATA(trans)
265
- ntrans = trans.shape[0 ]
266
-
267
260
# Determine whether each date lies left of the DST transition (store in
268
261
# result_a) or right of the DST transition (store in result_b)
269
- result_a, result_b = _get_utc_bounds(vals, tdata, ntrans, deltas)
262
+ result_a, result_b = _get_utc_bounds(vals, info. tdata, info. ntrans, info. deltas)
270
263
271
264
# silence false-positive compiler warning
272
265
dst_hours = np.empty(0 , dtype = np.int64)
@@ -278,7 +271,7 @@ timedelta-like}
278
271
# Shift the delta_idx by if the UTC offset of
279
272
# the target tz is greater than 0 and we're moving forward
280
273
# or vice versa
281
- first_delta = deltas[0 ]
274
+ first_delta = info. deltas[0 ]
282
275
if (shift_forward or shift_delta > 0 ) and first_delta > 0 :
283
276
delta_idx_offset = 1
284
277
elif (shift_backward or shift_delta < 0 ) and first_delta < 0 :
@@ -336,10 +329,10 @@ timedelta-like}
336
329
# nonexistent times
337
330
new_local = val - remaining_mins - 1
338
331
339
- delta_idx = bisect_right_i8(tdata, new_local, ntrans)
332
+ delta_idx = bisect_right_i8(info. tdata, new_local, info. ntrans)
340
333
341
334
delta_idx = delta_idx - delta_idx_offset
342
- result[i] = new_local - deltas[delta_idx]
335
+ result[i] = new_local - info. deltas[delta_idx]
343
336
elif fill_nonexist:
344
337
result[i] = NPY_NAT
345
338
else :
@@ -519,19 +512,7 @@ cdef ndarray[int64_t] _get_dst_hours(
519
512
# ----------------------------------------------------------------------
520
513
# Timezone Conversion
521
514
522
- def py_tz_convert_from_utc_single (int64_t utc_val , tzinfo tz ):
523
- # The 'bint* fold=NULL' in tz_convert_from_utc_single means we cannot
524
- # make it cdef, so this is version exposed for testing from python.
525
- return tz_convert_from_utc_single(utc_val, tz)
526
-
527
-
528
- @ cython.boundscheck (False )
529
- cdef int64_t tz_convert_from_utc_single(
530
- int64_t utc_val,
531
- tzinfo tz,
532
- bint* fold = NULL ,
533
- Py_ssize_t* outpos = NULL ,
534
- ) except ? - 1 :
515
+ cpdef int64_t tz_convert_from_utc_single(int64_t utc_val, tzinfo tz) except ? - 1 :
535
516
"""
536
517
Convert the val (in i8) from UTC to tz
537
518
@@ -541,8 +522,6 @@ cdef int64_t tz_convert_from_utc_single(
541
522
----------
542
523
utc_val : int64
543
524
tz : tzinfo
544
- fold : bint*, default NULL
545
- outpos : Py_ssize_t*, default NULL
546
525
547
526
Returns
548
527
-------
@@ -552,13 +531,8 @@ cdef int64_t tz_convert_from_utc_single(
552
531
Localizer info = Localizer(tz)
553
532
Py_ssize_t pos
554
533
555
- if utc_val == NPY_NAT:
556
- return utc_val
557
-
558
- if outpos is not NULL and info.use_pytz:
559
- return info.utc_val_to_local_val(utc_val, outpos, fold)
560
- else :
561
- return info.utc_val_to_local_val(utc_val, & pos, fold)
534
+ # Note: caller is responsible for ensuring utc_val != NPY_NAT
535
+ return info.utc_val_to_local_val(utc_val, & pos)
562
536
563
537
564
538
# OSError may be thrown by tzlocal on windows at or close to 1970-01-01
0 commit comments