-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: maybe_convert_objects mixed datetimes and timedeltas #27438
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 1 commit
9f0c986
f005531
e109dbf
034f729
d416771
f2f265e
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 |
---|---|---|
|
@@ -942,6 +942,7 @@ cdef class Seen: | |
|
||
cdef: | ||
bint int_ # seen_int | ||
bint nat_ # seen nat | ||
bint bool_ # seen_bool | ||
bint null_ # seen_null | ||
bint uint_ # seen_uint (unsigned integer) | ||
|
@@ -965,6 +966,7 @@ cdef class Seen: | |
initial methods to convert to numeric fail. | ||
""" | ||
self.int_ = 0 | ||
self.nat_ = 0 | ||
self.bool_ = 0 | ||
self.null_ = 0 | ||
self.uint_ = 0 | ||
|
@@ -1044,11 +1046,13 @@ cdef class Seen: | |
|
||
@property | ||
def is_bool(self): | ||
return not (self.datetime_ or self.numeric_ or self.timedelta_) | ||
return not (self.datetime_ or self.numeric_ or self.timedelta_ | ||
or self.nat_) | ||
|
||
@property | ||
def is_float_or_complex(self): | ||
return not (self.bool_ or self.datetime_ or self.timedelta_) | ||
return not (self.bool_ or self.datetime_ or self.timedelta_ | ||
or self.nat_) | ||
|
||
|
||
cdef _try_infer_map(v): | ||
|
@@ -1947,12 +1951,11 @@ def maybe_convert_objects(ndarray[object] objects, bint try_float=0, | |
seen.null_ = 1 | ||
floats[i] = complexes[i] = fnan | ||
elif val is NaT: | ||
seen.nat_ = 1 | ||
if convert_datetime: | ||
idatetimes[i] = NPY_NAT | ||
seen.datetime_ = 1 | ||
if convert_timedelta: | ||
itimedeltas[i] = NPY_NAT | ||
seen.timedelta_ = 1 | ||
if not (convert_datetime or convert_timedelta): | ||
seen.object_ = 1 | ||
break | ||
|
@@ -2046,11 +2049,18 @@ def maybe_convert_objects(ndarray[object] objects, bint try_float=0, | |
else: | ||
if not seen.bool_: | ||
if seen.datetime_: | ||
if not seen.numeric_: | ||
return datetimes | ||
if not seen.timedelta_: | ||
if not seen.numeric_: | ||
return datetimes | ||
elif seen.timedelta_: | ||
if not seen.numeric_: | ||
return timedeltas | ||
elif seen.nat_: | ||
if not seen.numeric_: | ||
if convert_datetime: | ||
return datetimes | ||
elif convert_timedelta: | ||
return timedeltas | ||
else: | ||
if seen.complex_: | ||
return complexes | ||
|
@@ -2077,11 +2087,18 @@ def maybe_convert_objects(ndarray[object] objects, bint try_float=0, | |
else: | ||
if not seen.bool_: | ||
if seen.datetime_: | ||
if not seen.numeric_: | ||
return datetimes | ||
if not seen.timedelta_: | ||
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. same as above 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. @jreback I've proposed simple test in corresponding issue that returns undesired output - this PR is aimed to resolve exactly such situations. Should I add this single test only? If not - 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. we already have quite a few tests so happy to merge tests first 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.
@jreback sorry but from your answer I still can't understand - is single test which is fixed by this PR enough or not? 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. yes this needs at least a single test if u want to do more comprehensive tests that xfail some (that re not passing now) is ok too (can be before or after this PR) 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. Will add. The problem with comprehensive tests: it cannot be done by hands -> it needs some "trusted" function to tested against i.e. needs copying old function for tests purposes only (as one of the options) - and here I don't understand may I do so or not. |
||
if not seen.numeric_: | ||
return datetimes | ||
elif seen.timedelta_: | ||
if not seen.numeric_: | ||
return timedeltas | ||
elif seen.nat_: | ||
if not seen.numeric_: | ||
if convert_datetime: | ||
return datetimes | ||
elif convert_timedelta: | ||
return timedeltas | ||
else: | ||
if seen.complex_: | ||
if not seen.int_: | ||
|
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 you make this 1 level higher elif's, its very hard to follow these branches currently
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.
Will do. As for me - this nested "if"s are ugly even before I've changed anything. Besides it is one of the good places to make a mistake (as it happens in current case).