-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Datetime error message (unable to continue that PR) #30711
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
Conversation
pandas/core/arrays/datetimes.py
Outdated
# GH#10720. If we failed to parse datetime then notify | ||
# that flag errors='coerce' could be used to NaT. | ||
# Trying to distinguish exception based on message. | ||
if "Unknown string format" in e.args[0]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use raise from
instead? I think makes things clearer with Python3
pandas/core/arrays/datetimes.py
Outdated
if "Unknown string format" in e.args[0]: | ||
msg = ( | ||
" ".join(e.args) | ||
+ ". You can coerce to NaT by passing errors='coerce'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's opt for f-strings over adding them like this
invalid_data = "Month 1, 1999" | ||
expected_args = ( | ||
f"Unknown string format: {invalid_data}. " | ||
f"You can coerce to NaT by passing errors='coerce'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f"You can coerce to NaT by passing errors='coerce'" | |
"You can coerce to NaT by passing errors='coerce'" |
Don't need the f prefix if not parametrizing anything
... raise from ...
Tests passed locally, but failed in Ci.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might help with the CI failure as well
pandas/core/arrays/datetimes.py
Outdated
# GH#10720. If we failed to parse datetime then notify | ||
# that flag errors='coerce' could be used to NaT. | ||
# Trying to distinguish exception based on message. | ||
msg = " ".join(e.args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
msg = " ".join(e.args) | |
msg = str(e) |
|
ping @WillAyd |
ping №2: @jbrockmendel |
@baevpetr ci is not passing |
pandas/core/tools/timedeltas.py
Outdated
@@ -113,9 +113,10 @@ def _coerce_scalar_to_timedelta_type(r, unit="ns", errors="raise"): | |||
|
|||
try: | |||
result = Timedelta(r, unit) | |||
except ValueError: | |||
except ValueError as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you call this "err" instead of "e". i really dislike 1-letter variable names
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even here. ok!)
invalid_data = "Month 1, 1999" | ||
expected_args = ( | ||
f"Unknown string format: {invalid_data}. " | ||
"You can coerce to NaT by passing errors='coerce'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like the "invalid_data" isnt making it into the error message in some of the tests
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff