@@ -607,11 +607,11 @@ cpdef array_to_datetime(
607
607
# to check if all arguments have the same tzinfo
608
608
tz = py_dt.utcoffset()
609
609
610
- except (ValueError , OverflowError ):
610
+ except (ValueError , OverflowError ) as err :
611
611
if is_coerce:
612
612
iresult[i] = NPY_NAT
613
613
continue
614
- raise TypeError ( " invalid string coercion to datetime" )
614
+ raise type (err)(f " invalid string coercion to datetime for \" {val} \" at position {i} " )
615
615
616
616
if tz is not None :
617
617
seen_datetime_offset = True
@@ -798,6 +798,7 @@ cdef _array_to_datetime_object(
798
798
# We return an object array and only attempt to parse:
799
799
# 1) NaT or NaT-like values
800
800
# 2) datetime strings, which we return as datetime.datetime
801
+ # 3) special strings - "now" & "today"
801
802
for i in range (n):
802
803
val = values[i]
803
804
if checknull_with_nat_and_na(val) or PyDateTime_Check(val):
@@ -811,17 +812,24 @@ cdef _array_to_datetime_object(
811
812
if len (val) == 0 or val in nat_strings:
812
813
oresult[i] = ' NaT'
813
814
continue
815
+
814
816
try :
815
- oresult[i] = parse_datetime_string(val, dayfirst = dayfirst,
817
+ # Handling special case strings today & now
818
+ if val == " today" :
819
+ oresult[i] = datetime.today()
820
+ elif val == " now" :
821
+ oresult[i] = datetime.now()
822
+ else :
823
+ oresult[i] = parse_datetime_string(val, dayfirst = dayfirst,
816
824
yearfirst = yearfirst)
817
- pydatetime_to_dt64(oresult[i], & dts)
818
- check_dts_bounds(& dts)
819
- except (ValueError , OverflowError ):
825
+ pydatetime_to_dt64(oresult[i], & dts)
826
+ check_dts_bounds(& dts)
827
+ except (ValueError , OverflowError ) as err :
820
828
if is_coerce:
821
829
oresult[i] = < object > NaT
822
830
continue
823
831
if is_raise:
824
- raise ValueError (f" Unable to parse string \" {val}\" at position {i}" )
832
+ raise type (err) (f" Unable to parse string \" {val}\" at position {i}" )
825
833
return values, None
826
834
else :
827
835
if is_raise:
0 commit comments