Skip to content

BUG: assert_index_equal ignoring names when check_order is false #47330

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
Jun 23, 2022

Conversation

phofl
Copy link
Member

@phofl phofl commented Jun 13, 2022

This should get merged after #47325 (will probably have a conflict then)

@phofl phofl added Bug Testing pandas testing functions or related to the test suite Dtype Conversions Unexpected or buggy dtype conversions Index Related to the Index class or subclasses labels Jun 13, 2022
)
else:
index = Index(array_sorted, name=index.name, dtype=index.dtype)
except TypeError:
Copy link
Member

Choose a reason for hiding this comment

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

maybe only have the safe_sort call in the try block?

Copy link
Member Author

Choose a reason for hiding this comment

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

A bit tricky, since array_sorted does not exist in the except block and we don't want to caste the Index again to an Index?

Copy link
Member

Choose a reason for hiding this comment

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

with an else block we would only cast if the safe_sort succeeded? (i.e. Index values are unique)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks very much. I am always forgetting that...

Changed the code

@@ -935,7 +935,7 @@ Other

.. ***DO NOT USE THIS SECTION***

-
- Bug in :func:`.assert_index_equal` with ``names=True`` and ``check_order=False`` not checking names not (:issue:`47328`)
Copy link
Member

Choose a reason for hiding this comment

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

DO NOT USE THIS SECTION

yep. this is ok here, in previous release notes the assert_* always go in the other section.

Copy link
Member Author

Choose a reason for hiding this comment

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

checked 1.3 notes to be sure there

-------
Index
"""
try:
Copy link
Member

Choose a reason for hiding this comment

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

following on from #47329 (comment)

is our use of safe_sort here, actually safe? i.e. we don't reach any of the cases that raise in safe_sort) and the try is not needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

None inside a mixed index still raises 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.

This gets adressed in #47331, we can probably remove the try there

Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

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

Thanks @phofl lgtm ex conflicts and ci failures.

@simonjayhawkins simonjayhawkins added this to the 1.5 milestone Jun 22, 2022
# Conflicts:
#	pandas/_testing/asserters.py
@phofl
Copy link
Member Author

phofl commented Jun 22, 2022

Resolved conflicts

@mroeschke mroeschke merged commit 3c100a5 into pandas-dev:main Jun 23, 2022
@mroeschke
Copy link
Member

Thanks @phofl

@phofl phofl deleted the 47328 branch June 24, 2022 10:22
yehoshuadimarsky pushed a commit to yehoshuadimarsky/pandas that referenced this pull request Jul 13, 2022
…das-dev#47330)

* BUG: assert_index_equal ignoring names when check_order is false

* Update doc/source/whatsnew/v1.5.0.rst

Co-authored-by: Simon Hawkins <[email protected]>

* Move index creation to else block

* Remove dtypes

Co-authored-by: Simon Hawkins <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Index Related to the Index class or subclasses Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: assert_index_equal loses names if check_order is False
3 participants