@@ -42,6 +42,7 @@ from pandas._libs.util cimport (
42
42
is_float_object,
43
43
is_integer_object,
44
44
)
45
+ import datetime as dt
45
46
46
47
from pandas._libs.tslibs.np_datetime import OutOfBoundsDatetime
47
48
from pandas._libs.tslibs.parsing import parse_datetime_string
@@ -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,23 @@ 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 checknull_with_nat_and_na(iresult[i]):
727
+ # GH 25978. No need to parse NaT-like or datetime-like vals
728
+ _result[i] = NPY_NAT
729
+ continue
730
+ _dt = dt.datetime.utcfromtimestamp(iresult[i]/ 1 _000_000_000)
731
+ if result_timezone[i] is not None :
732
+ _tzinfo = pytz.FixedOffset(result_timezone[i]/ 60 )
733
+ _result[i] = _dt.replace(tzinfo = pytz.UTC).astimezone(_tzinfo)
734
+ else :
735
+ _result[i] = _dt
736
+ print (" _dt" , _dt)
737
+ print (" resultimteinzei" , result_timezone[i])
738
+ print (" iresulti" , iresult[i])
739
+ print (" resulti" , result[i])
740
+ return _result, None
719
741
else :
720
742
tz_offset = out_tzoffset_vals.pop()
721
743
tz_out = pytz.FixedOffset(tz_offset / 60. )
0 commit comments