@@ -636,34 +636,41 @@ cdef inline int64_t[:] _tz_convert_dst(int64_t[:] values, tzinfo tz,
636
636
"""
637
637
cdef:
638
638
Py_ssize_t n = len (values)
639
- Py_ssize_t i, pos
639
+ Py_ssize_t i
640
+ int64_t[:] pos
640
641
int64_t[:] result = np.empty(n, dtype = np.int64)
641
642
ndarray[int64_t] trans
642
643
int64_t[:] deltas
643
644
int64_t v
645
+ bint tz_is_local
644
646
645
- if not is_tzlocal(tz):
647
+ tz_is_local = is_tzlocal(tz)
648
+
649
+ if not tz_is_local:
646
650
# get_dst_info cannot extract offsets from tzlocal because its
647
651
# dependent on a datetime
648
652
trans, deltas, _ = get_dst_info(tz)
649
653
if not to_utc:
650
654
# We add `offset` below instead of subtracting it
651
655
deltas = - 1 * np.array(deltas, dtype = ' i8' )
652
656
657
+ if not tz_is_local:
658
+ pos = trans.searchsorted(values, side = ' right' ) - 1
659
+
653
660
for i in range (n):
654
661
v = values[i]
655
662
if v == NPY_NAT:
656
663
result[i] = v
657
- elif is_tzlocal(tz) :
664
+ elif tz_is_local :
658
665
result[i] = _tz_convert_tzlocal_utc(v, tz, to_utc = to_utc)
659
666
else :
660
667
# TODO: Is it more efficient to call searchsorted pointwise or
661
668
# on `values` outside the loop? We are not consistent about this.
662
669
# relative effiency of pointwise increases with number of iNaTs
663
- pos = trans.searchsorted(v, side = ' right ' ) - 1
664
- if pos < 0 :
670
+
671
+ if pos[i] < 0 :
665
672
raise ValueError (' First time before start of DST info' )
666
- result[i] = v - deltas[pos]
673
+ result[i] = v - deltas[pos[i] ]
667
674
668
675
return result
669
676
@@ -1252,9 +1259,9 @@ def is_date_array_normalized(int64_t[:] stamps, object tz=None):
1252
1259
is_normalized : bool True if all stamps are normalized
1253
1260
"""
1254
1261
cdef:
1255
- Py_ssize_t pos, i, n = len (stamps)
1262
+ Py_ssize_t i, n = len (stamps)
1256
1263
ndarray[int64_t] trans
1257
- int64_t[:] deltas
1264
+ int64_t[:] deltas, pos
1258
1265
npy_datetimestruct dts
1259
1266
int64_t local_val, delta
1260
1267
str typ
@@ -1283,11 +1290,10 @@ def is_date_array_normalized(int64_t[:] stamps, object tz=None):
1283
1290
return False
1284
1291
1285
1292
else :
1293
+ pos = trans.searchsorted(stamps) - 1
1286
1294
for i in range (n):
1287
1295
# Adjust datetime64 timestamp, recompute datetimestruct
1288
- pos = trans.searchsorted(stamps[i]) - 1
1289
-
1290
- dt64_to_dtstruct(stamps[i] + deltas[pos], & dts)
1296
+ dt64_to_dtstruct(stamps[i] + deltas[pos[i]], & dts)
1291
1297
if (dts.hour + dts.min + dts.sec + dts.us) > 0 :
1292
1298
return False
1293
1299
0 commit comments