@@ -376,7 +376,8 @@ cpdef array_to_datetime(
376
376
bint dayfirst = False ,
377
377
bint yearfirst = False ,
378
378
bint utc = False ,
379
- bint require_iso8601 = False
379
+ bint require_iso8601 = False ,
380
+ bint allow_mixed = False ,
380
381
):
381
382
"""
382
383
Converts a 1D array of date-like values to a numpy array of either:
@@ -405,6 +406,8 @@ cpdef array_to_datetime(
405
406
indicator whether the dates should be UTC
406
407
require_iso8601 : bool, default False
407
408
indicator whether the datetime string should be iso8601
409
+ allow_mixed : bool, default False
410
+ Whether to allow mixed datetimes and integers.
408
411
409
412
Returns
410
413
-------
@@ -597,7 +600,7 @@ cpdef array_to_datetime(
597
600
return ignore_errors_out_of_bounds_fallback(values), tz_out
598
601
599
602
except TypeError :
600
- return array_to_datetime_object (values, errors, dayfirst, yearfirst)
603
+ return _array_to_datetime_object (values, errors, dayfirst, yearfirst)
601
604
602
605
if seen_datetime and seen_integer:
603
606
# we have mixed datetimes & integers
@@ -609,10 +612,12 @@ cpdef array_to_datetime(
609
612
val = values[i]
610
613
if is_integer_object(val) or is_float_object(val):
611
614
result[i] = NPY_NAT
615
+ elif allow_mixed:
616
+ pass
612
617
elif is_raise:
613
618
raise ValueError (" mixed datetimes and integers in passed array" )
614
619
else :
615
- return array_to_datetime_object (values, errors, dayfirst, yearfirst)
620
+ return _array_to_datetime_object (values, errors, dayfirst, yearfirst)
616
621
617
622
if seen_datetime_offset and not utc_convert:
618
623
# GH#17697
@@ -623,7 +628,7 @@ cpdef array_to_datetime(
623
628
# (with individual dateutil.tzoffsets) are returned
624
629
is_same_offsets = len (out_tzoffset_vals) == 1
625
630
if not is_same_offsets:
626
- return array_to_datetime_object (values, errors, dayfirst, yearfirst)
631
+ return _array_to_datetime_object (values, errors, dayfirst, yearfirst)
627
632
else :
628
633
tz_offset = out_tzoffset_vals.pop()
629
634
tz_out = pytz.FixedOffset(tz_offset / 60. )
@@ -670,7 +675,7 @@ cdef ignore_errors_out_of_bounds_fallback(ndarray[object] values):
670
675
671
676
@ cython.wraparound (False )
672
677
@ cython.boundscheck (False )
673
- cdef array_to_datetime_object (
678
+ cdef _array_to_datetime_object (
674
679
ndarray[object ] values,
675
680
str errors,
676
681
bint dayfirst = False ,
0 commit comments