Skip to content

Fix obj arguments in assertions #59460

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 4 commits into from
Sep 3, 2024

Conversation

serl
Copy link
Contributor

@serl serl commented Aug 9, 2024

@serl serl force-pushed the testing-obj-minor-fixes branch from 06a5393 to 8cfbede Compare August 9, 2024 13:54
Copy link
Member

@rhshadrach rhshadrach 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 - you good with this change?

@rhshadrach rhshadrach added Enhancement Testing pandas testing functions or related to the test suite labels Aug 12, 2024
@rhshadrach rhshadrach added this to the 3.0 milestone Aug 12, 2024
@serl
Copy link
Contributor Author

serl commented Aug 13, 2024

Hello @rhshadrach, thanks for your review!
I left the PR in the draft state as I feel like only the first line changed is actually tested, the two other changes didn't break any assert so I wanted to add more tests/asserts (but I didn't have time to tackle #59459 yet).
That said, I let you all decide if more work is needed here 🙂

Copy link
Contributor Author

@serl serl left a comment

Choose a reason for hiding this comment

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

I added a little test case and I'm quite satisfied with the results. @rhshadrach @mroeschke what are the next steps? 🚀

@@ -314,7 +314,7 @@ def _check_types(left, right, obj: str = "Index") -> None:
obj=lobj,
)
# get_level_values may change dtype
_check_types(left.levels[level], right.levels[level], obj=obj)
_check_types(left.levels[level], right.levels[level], obj=lobj)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't manage to write a test for this (type seems to be already checked just above), which, given its comment, smells very corner-case-y. Probably it's better to stop the head-banging, unless you have ideas on a test case, of course

@serl serl marked this pull request as ready for review August 26, 2024 07:42
@serl serl force-pushed the testing-obj-minor-fixes branch from 3ba3cd0 to 4c0c893 Compare August 26, 2024 07:44

MultiIndex level \\[1\\] values are different \\(25\\.0 %\\)
Index level \\[1\\] values are different \\(25\\.0 %\\)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I really like this change. I think MultiIndex level is clearer here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. Just to be on the same page, have you got the opportunity to skim #59440?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok so I tried to make a compromise (09a1ae5), which in short is:

root_obj = "MultiIndex" if obj == "Index" else obj
...
lobj = f"{root_obj} level [{level}]"

I find that a little brittle, as it is based on the fact that about a hundred lines before there is obj: str = "Index".

...So I tried harder (ad99297), which correspond to the current state of the PR. That is having the obj in the assert_index_equal function definition being None by default and branching immediately:

    if obj is None:
        obj = "MultiIndex" if isinstance(left, MultiIndex) else "Index"

Thoughts? Better ideas?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello @mroeschke, have you got the chance to check this? Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I really like this change. I think MultiIndex level is clearer here

No disagreement that it is slightly clearer, but it bucks the otherwise consistent behavior of assert_.*_equal utilizing obj when passed.

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.

Sure in the scheme of things the difference is minor, but the obj use consistency is a plus.

@mroeschke mroeschke merged commit 13578bf into pandas-dev:main Sep 3, 2024
47 checks passed
@mroeschke
Copy link
Member

Thanks @serl

@serl serl deleted the testing-obj-minor-fixes branch September 4, 2024 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement 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_frame_equal does not include the obj parameter in error when a MultiIndex is different
3 participants