Skip to content

Added improvements in to_datetime Error reporting message #47597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ cpdef array_to_datetime(
continue
elif is_raise:
raise ValueError(
f"time data {val} doesn't match format specified"
f"time data \"{val}\" at position {i} doesn't match format specified"
)
return values, tz_out

Expand Down Expand Up @@ -664,11 +664,11 @@ cpdef array_to_datetime(

# Still raise OutOfBoundsDatetime,
# as error message is informative.
raise
raise OutOfBoundsDatetime(f"Cannot convert \"{val}\" at position {i} to datetime")

assert is_ignore
return values, tz_out
raise
raise OutOfBoundsDatetime(f"Cannot convert \"{val}\" at position {i} to datetime")

except OutOfBoundsDatetime:
if is_raise:
Expand Down Expand Up @@ -821,7 +821,7 @@ cdef _array_to_datetime_object(
oresult[i] = <object>NaT
continue
if is_raise:
raise
raise ValueError(f"Unable to parse string \"{val}\" at position {i}")
return values, None
else:
if is_raise:
Expand Down
7 changes: 6 additions & 1 deletion pandas/_libs/tslibs/parsing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,12 @@ def parse_datetime_string(
pass

try:
dt = du_parse(date_string, default=_DEFAULT_DATETIME,
if date_string == "today":
dt = datetime.today()
elif date_string == "now":
dt = datetime.now()
else:
dt = du_parse(date_string, default=_DEFAULT_DATETIME,
dayfirst=dayfirst, yearfirst=yearfirst, **kwargs)
except TypeError:
# following may be raised from dateutil
Expand Down