-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: Fix mixed datetime dtype inference #33749
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
is the docbuild failure real or a fluke? |
Nevermind, was a typo in whatsnew that caused it |
pandas/core/indexes/datetimes.py
Outdated
other = DatetimeIndex(other) | ||
try: | ||
other = DatetimeIndex(other) | ||
except OutOfBoundsDatetime: |
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.
what is hitting this? why are we not bubbling this up?
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.
Cases where we have a datetime.date that's out of bounds for DatetimeIndex (e.g. https://github.com/pandas-dev/pandas/pull/33749/files#diff-0c5fadf83f91d24a931a051d82801917R569) are raising here instead of returning -1 which I believe is a bug on master (that's what @jschendel and I were talking about above). I don't think we'd want this to actually raise since it doesn't seem to be an essential step.
) | ||
def test_infer_dtype_date_order_invariant(self, values): | ||
# https://github.com/pandas-dev/pandas/issues/33741 | ||
result = lib.infer_dtype(values, skipna=True) |
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.
add NaT and parameterize on skipna as well
needs a rebase as well |
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.
i guess this is ok. cc @jbrockmendel
pandas/core/indexes/base.py
Outdated
@@ -4662,7 +4662,11 @@ def _maybe_promote(self, other: "Index"): | |||
""" | |||
|
|||
if self.inferred_type == "date" and isinstance(other, ABCDatetimeIndex): | |||
return type(other)(self), other | |||
try: | |||
maybe_casted = type(other)(self) |
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.
write this as
try:
return type(other)(self)
except OutOfBoundsDatetime:
pass
return Index(self), other
as it needs to copy
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.
minor comment, ping on green.
pandas/_libs/lib.pyx
Outdated
return "datetime" | ||
if is_date_array(values, skipna=skipna): |
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 be elif
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.
Fixed
@jreback ping |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff