Skip to content

Commit d25d7fb

Browse files
committed
Added improvements in to_datetime Error reporting message - incorrect field now/today shown as error
1 parent f11a5d2 commit d25d7fb

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

pandas/_libs/tslib.pyx

+10-3
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,7 @@ cdef _array_to_datetime_object(
798798
# We return an object array and only attempt to parse:
799799
# 1) NaT or NaT-like values
800800
# 2) datetime strings, which we return as datetime.datetime
801+
# 3) special strings - "now" & "today"
801802
for i in range(n):
802803
val = values[i]
803804
if checknull_with_nat_and_na(val) or PyDateTime_Check(val):
@@ -812,10 +813,16 @@ cdef _array_to_datetime_object(
812813
oresult[i] = 'NaT'
813814
continue
814815
try:
815-
oresult[i] = parse_datetime_string(val, dayfirst=dayfirst,
816+
# Handling special case strings today & now
817+
if val == "today":
818+
oresult[i] = datetime.today()
819+
elif val == "now":
820+
oresult[i] = datetime.now()
821+
else:
822+
oresult[i] = parse_datetime_string(val, dayfirst=dayfirst,
816823
yearfirst=yearfirst)
817-
pydatetime_to_dt64(oresult[i], &dts)
818-
check_dts_bounds(&dts)
824+
pydatetime_to_dt64(oresult[i], &dts)
825+
check_dts_bounds(&dts)
819826
except (ValueError, OverflowError):
820827
if is_coerce:
821828
oresult[i] = <object>NaT

0 commit comments

Comments
 (0)