@@ -12,6 +12,7 @@ from cpython.object cimport PyObject
12
12
import_datetime()
13
13
14
14
15
+ import dateutil
15
16
cimport numpy as cnp
16
17
from numpy cimport (
17
18
float64_t,
@@ -516,6 +517,7 @@ cpdef array_to_datetime(
516
517
assert is_raise or is_ignore or is_coerce
517
518
518
519
result = np.empty(n, dtype = " M8[ns]" )
520
+ result_timezone = np.empty(n, dtype = " object" )
519
521
iresult = result.view(" i8" )
520
522
521
523
try :
@@ -633,10 +635,12 @@ cpdef array_to_datetime(
633
635
# dateutil timezone objects cannot be hashed, so
634
636
# store the UTC offsets in seconds instead
635
637
out_tzoffset_vals.add(tz.total_seconds())
638
+ result_timezone[i] = tz.total_seconds()
636
639
else :
637
640
# Add a marker for naive string, to track if we are
638
641
# parsing mixed naive and aware strings
639
642
out_tzoffset_vals.add(" naive" )
643
+ result_timezone[i] = None
640
644
641
645
_ts = convert_datetime_to_tsobject(py_dt, None )
642
646
iresult[i] = _ts.value
@@ -650,6 +654,7 @@ cpdef array_to_datetime(
650
654
# since we store the total_seconds of
651
655
# dateutil.tz.tzoffset objects
652
656
out_tzoffset_vals.add(out_tzoffset * 60. )
657
+ result_timezone[i] = out_tzoffset * 60.
653
658
tz = pytz.FixedOffset(out_tzoffset)
654
659
value = tz_localize_to_utc_single(value, tz)
655
660
out_local = 0
@@ -658,6 +663,7 @@ cpdef array_to_datetime(
658
663
# Add a marker for naive string, to track if we are
659
664
# parsing mixed naive and aware strings
660
665
out_tzoffset_vals.add(" naive" )
666
+ result_timezone[i] = None
661
667
iresult[i] = value
662
668
check_dts_bounds(& dts)
663
669
@@ -715,7 +721,18 @@ cpdef array_to_datetime(
715
721
# (with individual dateutil.tzoffsets) are returned
716
722
is_same_offsets = len (out_tzoffset_vals) == 1
717
723
if not is_same_offsets:
718
- return _array_to_datetime_object(values, errors, dayfirst, yearfirst)
724
+ _result = np.empty(n, dtype = " object" )
725
+ for i in range (n):
726
+ if iresult[i] == NPY_NAT:
727
+ _result[i] = NaT
728
+ continue
729
+ _dt = parse_datetime_string(str (result[i]))
730
+ if result_timezone[i] is not None :
731
+ _tzinfo = dateutil.tz.tzoffset(None , result_timezone[i])
732
+ _result[i] = _dt.replace(tzinfo = pytz.UTC).astimezone(_tzinfo)
733
+ else :
734
+ _result[i] = _dt
735
+ return _result, None
719
736
else :
720
737
tz_offset = out_tzoffset_vals.pop()
721
738
tz_out = pytz.FixedOffset(tz_offset / 60. )
0 commit comments