You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In [10]: pd.to_timedelta(['apple', '1 day'], errors='ignore')
...
ValueError: unit abbreviation w/o a number
In [12]: pd.to_timedelta(['apple', pd.Timedelta('1day')], errors='ignore')
...
ValueError: unit abbreviation w/o a number
It's the same error as you get with errors='raise' (so not captured somewhere), errors='coerce is working correctly.
The text was updated successfully, but these errors were encountered:
The reason is because errors='ignore', is well, ignored. I think I would just wrap the current try-except logic as follows:
try:
try:
foriinrange(n):
result[i] =parse_timedelta_string(values[i]) # always raiseexceptException:
foriinrange(n):
result[i] =convert_to_timedelta64(values[i], unit, is_coerce)
exceptException: # when is_coerce=Falseiferrors=='raise':
raiseeliferrors=='ignore':
returnvaluesreturniresult
The reason is that one could consider the original try-except block as the process through which we convert to timedelta, then all three options for errors are satisfied:
errors='raise'
Try to convert via method 1, which fails, so we try with method 2. If that fails, we raise the exception.
errors='coerce' --> is_coerce=True
Try to convert via method 1, which fails, so we try with method 2. In method 2, if converting one of the elements fails, we return NPY_NAT.
errors='ignore'
Try to convert via method 1, which fails, so we try with method 2. If that fails, we just return the original values array as promised in documentation.
From the added docs in #13425:
It's the same error as you get with
errors='raise'
(so not captured somewhere),errors='coerce
is working correctly.The text was updated successfully, but these errors were encountered: