Skip to content

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

Merged
merged 5 commits into from
Sep 14, 2022

Conversation

phofl
Copy link
Member

@phofl phofl commented Sep 7, 2022

  • closes #xxxx (Replace xxxx with the Github issue number)
  • Tests added and passed if fixing a bug or adding a new feature
  • All code checks passed.
  • Added type annotations to new arguments/methods/functions.
  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.

This came up when working on MultiIndex.union with ea. Gets converted into a Index of tuples and then raising the error. The added check is a last resort before raising to avoid impacting performance negatively.

@phofl phofl added Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate NA - MaskedArrays Related to pd.NA and nullable extension arrays labels Sep 7, 2022
return False

for left_element, right_element in zip(left, right):
if left_element is C_NA and not right_element is C_NA:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not right_element is C_NA -> right_element is not C_NA

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx

@@ -659,7 +660,11 @@ 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
return False
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

if not isinstance(left, tuple) or not isinstance(right, tuple):
return False

for left_element, right_element in zip(left, right):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this assert that len(left) == len(right)? Guessing this is assumed upstream but technically (1, NA) and (1,) would return False

Copy link
Member Author

Choose a reason for hiding this comment

The 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

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mroeschke mroeschke added this to the 1.6 milestone Sep 13, 2022
@phofl
Copy link
Member Author

phofl commented Sep 13, 2022

Ok to merge on greenish?

@mroeschke mroeschke merged commit 5e2e92e into pandas-dev:main Sep 14, 2022
@mroeschke
Copy link
Member

Thanks @phofl

@phofl phofl deleted the index_equals_tuples_na branch September 14, 2022 19:00
@@ -168,7 +168,7 @@ Indexing

Missing
^^^^^^^
-
- Bug in :meth:`Index.equals` raising ``TypeError` when :class:`Index` consists of tuples that contain ``NA`` (:issue:`48446`)
Copy link
Member

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.

@mroeschke mroeschke modified the milestones: 1.6, 2.0 Oct 13, 2022
noatamir pushed a commit to noatamir/pandas that referenced this pull request Nov 9, 2022
…s-dev#48446)

* BUG: Index.equals raising with index of tuples that contain NA

* Adress review

* Add sanity check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate NA - MaskedArrays Related to pd.NA and nullable extension arrays
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants