-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Index.equals raising with index of tuples that contain NA #48446
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 3 commits
9f7e022
0e52188
2d7c9a4
626f1dc
53a929f
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 |
---|---|---|
|
@@ -31,6 +31,7 @@ from cython cimport ( | |
floating, | ||
) | ||
|
||
from pandas._libs.missing import check_na_tuples_nonequal | ||
from pandas.util._exceptions import find_stack_level | ||
|
||
import_datetime() | ||
|
@@ -649,7 +650,7 @@ def array_equivalent_object(left: object[:], right: object[:]) -> bool: | |
or is_matching_na(x, y, nan_matches_none=True) | ||
): | ||
return False | ||
except ValueError: | ||
except (ValueError, TypeError): | ||
# Avoid raising ValueError when comparing Numpy arrays to other types | ||
if cnp.PyArray_IsAnyScalar(x) != cnp.PyArray_IsAnyScalar(y): | ||
# Only compare scalars to scalars and non-scalars to non-scalars | ||
|
@@ -658,7 +659,12 @@ def array_equivalent_object(left: object[:], right: object[:]) -> bool: | |
and not (isinstance(x, type(y)) or isinstance(y, type(x)))): | ||
# Check if non-scalars have the same type | ||
return False | ||
elif check_na_tuples_nonequal(x, y): | ||
# We have tuples where one Side has a NA and the other side does not | ||
# Only condition we may end up with a TypeError | ||
return False | ||
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. comment that this is the only/main we we expect to get a TypeError 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. Added |
||
raise | ||
|
||
return True | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,34 @@ cdef: | |
type cDecimal = Decimal # for faster isinstance checks | ||
|
||
|
||
cpdef bint check_na_tuples_nonequal(object left, object right): | ||
""" | ||
When we have NA in one of the tuples but not the other we have to check here, | ||
because our regular checks fail before with ambigous boolean value. | ||
|
||
Parameters | ||
---------- | ||
left: Any | ||
right: Any | ||
|
||
Returns | ||
------- | ||
True if we are dealing with tuples that have NA on one side and non NA on | ||
the other side. | ||
|
||
""" | ||
if not isinstance(left, tuple) or not isinstance(right, tuple): | ||
return False | ||
|
||
for left_element, right_element in zip(left, right): | ||
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. Should this assert that 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. Added. I think we could end up here with weird combinations, so better to be a bit more explicit |
||
if left_element is C_NA and right_element is not C_NA: | ||
return True | ||
elif right_element is C_NA and left_element is not C_NA: | ||
return True | ||
|
||
return False | ||
|
||
|
||
cpdef bint is_matching_na(object left, object right, bint nan_matches_none=False): | ||
""" | ||
Check if two scalars are both NA of matching types. | ||
|
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.
looks like this is not rendering correctly due to unbalanced backticks around TypeError.