@@ -33,7 +33,7 @@ from pandas._libs.tslibs.timedeltas cimport (cast_from_unit,
33
33
delta_to_nanoseconds)
34
34
from pandas._libs.tslibs.timezones cimport (
35
35
is_utc, is_tzlocal, is_fixed_offset, get_utcoffset, get_dst_info,
36
- get_timezone, maybe_get_tz, tz_compare)
36
+ get_timezone, maybe_get_tz, tz_compare, get_tzlocal_tz )
37
37
from pandas._libs.tslibs.timezones import UTC
38
38
from pandas._libs.tslibs.parsing import parse_datetime_string
39
39
@@ -541,9 +541,19 @@ cdef inline void localize_tso(_TSObject obj, tzinfo tz):
541
541
int64_t local_val
542
542
Py_ssize_t pos
543
543
str typ
544
+ bint tz_changed
544
545
545
546
assert obj.tzinfo is None
546
547
548
+ orig_tz = tz
549
+ tz_changed = False
550
+
551
+ if is_tzlocal(tz):
552
+ new_tz = get_tzlocal_tz(tz)
553
+ if new_tz != tz:
554
+ tz_changed = True
555
+ tz = new_tz
556
+
547
557
if is_utc(tz):
548
558
pass
549
559
elif obj.value == NPY_NAT:
@@ -574,7 +584,12 @@ cdef inline void localize_tso(_TSObject obj, tzinfo tz):
574
584
# so this branch will never be reached.
575
585
pass
576
586
577
- obj.tzinfo = tz
587
+ if tz_changed:
588
+ # We want to return tzlocal() if provided it, even if we map it
589
+ # to a real tz for performance reasons
590
+ obj.tzinfo = orig_tz
591
+ else :
592
+ obj.tzinfo = tz
578
593
579
594
580
595
cdef inline datetime _localize_pydatetime(datetime dt, tzinfo tz):
@@ -652,6 +667,9 @@ cdef inline int64_t[:] _tz_convert_dst(int64_t[:] values, tzinfo tz,
652
667
bint tz_is_local
653
668
654
669
tz_is_local = is_tzlocal(tz)
670
+ if tz_is_local:
671
+ tz = get_tzlocal_tz(tz)
672
+ tz_is_local = is_tzlocal(tz)
655
673
656
674
if not tz_is_local:
657
675
# get_dst_info cannot extract offsets from tzlocal because its
@@ -763,6 +781,11 @@ cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2):
763
781
if val == NPY_NAT:
764
782
return val
765
783
784
+ if is_tzlocal(tz1):
785
+ tz1 = get_tzlocal_tz(tz1)
786
+ if is_tzlocal(tz2):
787
+ tz2 = get_tzlocal_tz(tz2)
788
+
766
789
# Convert to UTC
767
790
if is_tzlocal(tz1):
768
791
utc_date = _tz_convert_tzlocal_utc(val, tz1, to_utc = True )
@@ -807,10 +830,16 @@ cdef inline int64_t[:] _tz_convert_one_way(int64_t[:] vals, object tz,
807
830
int64_t[:] converted, result
808
831
Py_ssize_t i, n = len (vals)
809
832
int64_t val
833
+ bint tz_is_local
834
+
835
+ tz_is_local = is_tzlocal(tz)
836
+ if tz_is_local:
837
+ tz = get_tzlocal_tz(tz)
838
+ tz_is_local = is_tzlocal(tz)
810
839
811
840
if not is_utc(get_timezone(tz)):
812
841
converted = np.empty(n, dtype = np.int64)
813
- if is_tzlocal(tz) :
842
+ if tz_is_local :
814
843
for i in range (n):
815
844
val = vals[i]
816
845
if val == NPY_NAT:
@@ -915,6 +944,9 @@ def tz_localize_to_utc(ndarray[int64_t] vals, object tz, object ambiguous=None,
915
944
916
945
result = np.empty(n, dtype = np.int64)
917
946
947
+ if is_tzlocal(tz):
948
+ tz = get_tzlocal_tz(tz)
949
+
918
950
if is_tzlocal(tz):
919
951
for i in range (n):
920
952
v = vals[i]
@@ -1222,6 +1254,9 @@ cdef int64_t[:] _normalize_local(int64_t[:] stamps, tzinfo tz):
1222
1254
npy_datetimestruct dts
1223
1255
int64_t delta, local_val
1224
1256
1257
+ if is_tzlocal(tz):
1258
+ tz = get_tzlocal_tz(tz)
1259
+
1225
1260
if is_tzlocal(tz):
1226
1261
for i in range (n):
1227
1262
if stamps[i] == NPY_NAT:
@@ -1301,6 +1336,9 @@ def is_date_array_normalized(int64_t[:] stamps, object tz=None):
1301
1336
int64_t local_val, delta
1302
1337
str typ
1303
1338
1339
+ if is_tzlocal(tz):
1340
+ tz = get_tzlocal_tz(tz)
1341
+
1304
1342
if tz is None or is_utc(tz):
1305
1343
for i in range (n):
1306
1344
dt64_to_dtstruct(stamps[i], & dts)
0 commit comments