-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: lib.infer_dtype with incompatible intervals #41749
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 |
---|---|---|
|
@@ -2029,16 +2029,59 @@ cdef bint is_period_array(ndarray[object] values): | |
return True | ||
|
||
|
||
cdef class IntervalValidator(Validator): | ||
cdef inline bint is_value_typed(self, object value) except -1: | ||
return is_interval(value) | ||
|
||
|
||
cpdef bint is_interval_array(ndarray values): | ||
""" | ||
Is this an ndarray of Interval (or np.nan) with a single dtype? | ||
""" | ||
|
||
cdef: | ||
IntervalValidator validator = IntervalValidator(len(values), | ||
skipna=True) | ||
return validator.validate(values) | ||
Py_ssize_t i, n = len(values) | ||
str closed = None | ||
bint numeric = False | ||
bint dt64 = False | ||
bint td64 = False | ||
object val | ||
|
||
if len(values) == 0: | ||
return False | ||
|
||
for val in values: | ||
if is_interval(val): | ||
if closed is None: | ||
closed = val.closed | ||
numeric = ( | ||
util.is_float_object(val.left) | ||
or util.is_integer_object(val.left) | ||
) | ||
td64 = is_timedelta(val.left) | ||
dt64 = PyDateTime_Check(val.left) | ||
elif val.closed != closed: | ||
# mismatched closedness | ||
return False | ||
elif numeric: | ||
if not ( | ||
util.is_float_object(val.left) | ||
or util.is_integer_object(val.left) | ||
): | ||
# i.e. datetime64 or timedelta64 | ||
return False | ||
elif td64: | ||
if not is_timedelta(val.left): | ||
return False | ||
elif dt64: | ||
if not PyDateTime_Check(val.left): | ||
return False | ||
else: | ||
raise ValueError(val) | ||
elif util.is_nan(val) or val is 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. couldn't this be a float nan or NA? (or None)? i am not sure we really specify 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. this matches what we do in corresponding libinterval function 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. got it but out of scope for this PR |
||
pass | ||
else: | ||
return False | ||
|
||
if closed is None: | ||
# we saw all-NAs, no actual Intervals | ||
return False | ||
return True | ||
|
||
|
||
@cython.boundscheck(False) | ||
|
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 remove the IntervalValidator code?
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, will add that to the upcoming misc branch
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.
kk