-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: add option to tz_localize to return NaT instead of raising a NonExistentTimeError #13057
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
Comments
pls show an example tz_localize already has the ambiguous argument for this purpose |
and pd.show_versions() |
Here is a minimal example import pandas as pd
df = pd.DataFrame({'large_series': [pd.Timestamp('2015-03-08 02:30:00')]})
ind = pd.DatetimeIndex(df['large_series'])
ind = ind.tz_localize('America/Los_Angeles') (imagine that
Note that the exception is
|
so you want a ok I suppose, though this indicates a fundamental issue that you have. I don't think hiding this is the right answer. How did you generate this in the first place? cc @rockg |
Exactly. I got the data from an external source (here, if you are interested). There are just a few timestamps out of 500k that are a few minutes after 2am on the day when DST becomes active, so I believe they are just an error in the dataset |
ok, unless other objections, I don't see adding a coercion option as a problem. pull-requests welcome! |
Here it is #13058. Hopefully, I didn't miss anything, as it is my first time contributing to a large OSS project. |
It would be nice if the
tz_localize
function of aDatetimeIndex
had an optional flag for silently returningNaT
instead of throwing aNonExistentTimeError
, if the timestamp is not valid in the given timezone (for example due to DST changes).I ran into this problem while trying to
tz_localize
a large index, and it seems to me that this would be a much better solution than manually handling the exception with a lambda expression in a (slow) python loop.The text was updated successfully, but these errors were encountered: