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
ValueError due to Timestamp.strftime are currently silently caught by DatetimeLike array strftime and replaced with str(t). This leads to unexpected behaviour:
# Use datetime.str, that returns ts.isoformat(sep=' ')
res =str(ts)
Note that this try-except is around since 0.16.1 (introduced by commit 3d54482)
This "questionable behaviour" was also reported in #48588
Note that this does not happen with dates that cannot be converted to datetime at all, because this particular ValueError is currently caught and turned into a NotImplementedError:
>dta=pd.DatetimeIndex(np.array(['-0020-01-01', '2020-01-02'], 'datetime64[s]'))
>dta.strftime("%Y_%m_%d") # Custom so falls back on Timestamp.strftimeNotImplementedError: strftimenotyetsupportedonTimestampswhichareoutsidetherangeofPython'sstandardlibrary. Fornow, pleasecallthecomponentsyouneed (suchas`.year`and`.month`) andconstructyourstringfromthere.
>dta[0].strftime("%Y_%m_%d")
NotImplementedError: strftimenotyetsupportedonTimestampswhichareoutsidetherangeofPython'sstandardlibrary. Fornow, pleasecallthecomponentsyouneed (suchas`.year`and`.month`) andconstructyourstringfromthere.
Feature Description
I propose to add an errors parameter to array strftime with the following values
‘raise’ (default) would not catch any underlying error and raise them as is
‘ignore’ would catch all errors and silently replace the output with None instead of a string
'warn' would have the same behaviour as 'ignore' and would additionally issue a StrftimeErrorWarning warning message "The following timestamps could be converted to string: [...]. Set errors=‘raise’ to see the details"
The specific NotImplementedError described previously can either disappear or stay, but in any case it should be handled the same way than ValueErrors above (meaning that if user selects 'ignore', the error must be silently caught)
Alternative Solutions
An alternative solution could be to always raise errors
Additional Context
No response
The text was updated successfully, but these errors were encountered:
Feature Type
Adding new functionality to pandas
Changing existing functionality in pandas
Removing existing functionality in pandas
Problem Description
ValueError
due toTimestamp.strftime
are currently silently caught by DatetimeLike array strftime and replaced withstr(t)
. This leads to unexpected behaviour:This very surprising behaviour on the array strftime is due to the try-except at
pandas/pandas/_libs/tslib.pyx
Lines 219 to 224 in b8a4691
Note that this try-except is around since 0.16.1 (introduced by commit 3d54482)
This "questionable behaviour" was also reported in #48588
Note that this does not happen with dates that cannot be converted to
datetime
at all, because this particularValueError
is currently caught and turned into aNotImplementedError
:Feature Description
I propose to add an
errors
parameter to arraystrftime
with the following valuesStrftimeErrorWarning
warning message"The following timestamps could be converted to string: [...]. Set errors=‘raise’ to see the details"
The specific
NotImplementedError
described previously can either disappear or stay, but in any case it should be handled the same way than ValueErrors above (meaning that if user selects 'ignore', the error must be silently caught)Alternative Solutions
An alternative solution could be to always raise errors
Additional Context
No response
The text was updated successfully, but these errors were encountered: