@@ -519,7 +519,12 @@ cpdef array_to_datetime(
519
519
iresult[i] = _ts.value
520
520
521
521
tz = _ts.tzinfo
522
- if tz is not None :
522
+ if _ts.value == NPY_NAT:
523
+ # e.g. "NaT" string or empty string, we do not consider
524
+ # this as either tzaware or tznaive. See
525
+ # test_to_datetime_with_empty_str_utc_false_format_mixed
526
+ pass
527
+ elif tz is not None :
523
528
# dateutil timezone objects cannot be hashed, so
524
529
# store the UTC offsets in seconds instead
525
530
nsecs = tz.utcoffset(None ).total_seconds()
@@ -610,7 +615,6 @@ cdef _array_to_datetime_object(
610
615
# 1) NaT or NaT-like values
611
616
# 2) datetime strings, which we return as datetime.datetime
612
617
# 3) special strings - "now" & "today"
613
- unique_timezones = set ()
614
618
for i in range (n):
615
619
# Analogous to: val = values[i]
616
620
val = < object > (< PyObject** > cnp.PyArray_MultiIter_DATA(mi, 1 ))[0 ]
@@ -640,7 +644,6 @@ cdef _array_to_datetime_object(
640
644
tzinfo = tsobj.tzinfo,
641
645
fold = tsobj.fold,
642
646
)
643
- unique_timezones.add(tsobj.tzinfo)
644
647
645
648
except (ValueError , OverflowError ) as ex:
646
649
ex.args = (f" {ex}, at position {i}" , )
@@ -658,16 +661,15 @@ cdef _array_to_datetime_object(
658
661
659
662
cnp.PyArray_MultiIter_NEXT(mi)
660
663
661
- if len (unique_timezones) > 1 :
662
- warnings.warn(
663
- " In a future version of pandas, parsing datetimes with mixed time "
664
- " zones will raise an error unless `utc=True`. "
665
- " Please specify `utc=True` to opt in to the new behaviour "
666
- " and silence this warning. To create a `Series` with mixed offsets and "
667
- " `object` dtype, please use `apply` and `datetime.datetime.strptime`" ,
668
- FutureWarning ,
669
- stacklevel = find_stack_level(),
670
- )
664
+ warnings.warn(
665
+ " In a future version of pandas, parsing datetimes with mixed time "
666
+ " zones will raise an error unless `utc=True`. "
667
+ " Please specify `utc=True` to opt in to the new behaviour "
668
+ " and silence this warning. To create a `Series` with mixed offsets and "
669
+ " `object` dtype, please use `apply` and `datetime.datetime.strptime`" ,
670
+ FutureWarning ,
671
+ stacklevel = find_stack_level(),
672
+ )
671
673
return oresult_nd, None
672
674
673
675
0 commit comments