-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
REGR: to_datetime, unique with OOB values #31520
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
is_categorical_dtype, | ||
is_complex_dtype, | ||
is_datetime64_any_dtype, | ||
is_datetime64_dtype, | ||
is_datetime64_ns_dtype, | ||
is_extension_array_dtype, | ||
is_float_dtype, | ||
|
@@ -191,6 +192,11 @@ def _reconstruct_data(values, dtype, original): | |
if isinstance(original, ABCIndexClass): | ||
values = values.astype(object, copy=False) | ||
elif dtype is not None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is period an issue here? (just comments, can target master) |
||
if is_datetime64_dtype(dtype): | ||
dtype = "datetime64[ns]" | ||
elif is_timedelta64_dtype(dtype): | ||
dtype = "timedelta64[ns]" | ||
|
||
values = values.astype(dtype, copy=False) | ||
|
||
return values | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -602,7 +602,9 @@ def to_datetime( | |
cache : bool, default True | ||
If True, use a cache of unique, converted dates to apply the datetime | ||
conversion. May produce significant speed-up when parsing duplicate | ||
date strings, especially ones with timezone offsets. | ||
date strings, especially ones with timezone offsets. The cache is only | ||
used when there are at least 50 values. The presence of out-of-bounds | ||
values will render the cache unusable and may slow down parsing. | ||
|
||
.. versionadded:: 0.23.0 | ||
|
||
|
@@ -734,7 +736,17 @@ def to_datetime( | |
convert_listlike = partial(convert_listlike, name=arg.name) | ||
result = convert_listlike(arg, format) | ||
elif is_list_like(arg): | ||
cache_array = _maybe_cache(arg, format, cache, convert_listlike) | ||
try: | ||
cache_array = _maybe_cache(arg, format, cache, convert_listlike) | ||
except tslibs.OutOfBoundsDatetime: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is the best we can do here, at least without major surgery. It'll involve double-parsing the input for large arrays with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, pls create an issue as this should be handled directly in _maybe_cache itself |
||
# caching attempts to create a DatetimeIndex, which may raise | ||
# an OOB. If that's the desired behavior, then just reraise... | ||
if errors == "raise": | ||
raise | ||
# ... otherwise, continue without the cache. | ||
from pandas import Series | ||
|
||
cache_array = Series([], dtype=object) # just an empty array | ||
if not cache_array.empty: | ||
result = _convert_and_box_cache(arg, cache_array) | ||
else: | ||
|
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.
This was present in 0.25.3, so technically not a regression.
Do we want to collect fixed regression in a dedicated section? I think we've done that in the past.
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.
sure would be a-ok