Skip to content

BUG: Fix TypeError in assert_index_equal when comparing CategoricalIndex with check_categorical=True and exact=False #61941

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

Aniketsy
Copy link

#61935

  • Fixes a bug where assert_index_equal raises a TypeError instead of AssertionError when comparing two CategoricalIndex objects with check_categorical=True and exact=False.

  • Ensures consistency with expected testing behavior by properly raising an AssertionError in these cases.

Please let me know if my approach or fix needs any improvements . I’m open to feedback and happy to make changes based on suggestions.

@Aniketsy
Copy link
Author

Hi @mroeschke
I've opened a pull request addressing
BUG: Fix TypeError in assert_index_equal when comparing CategoricalIndex with check_categorical=True and exact=False ([#61941])
The changes are ready for review.

I'd really appreciate it if you could take a look and provide feedback .
Please let me know if anything needs to be improved or clarified.

Thanks!

@mroeschke mroeschke added the Testing pandas testing functions or related to the test suite label Jul 25, 2025
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.

This also needs a unit test

@Aniketsy Aniketsy force-pushed the bugfix-assert-categoricalindex-typeerror branch from 333eb89 to 5edf8ce Compare July 25, 2025 18:06
@Aniketsy
Copy link
Author

Hi @mroeschke,

Thank you for your review. I’ve updated the PR based on your feedback ,please have a look when convenient.

Additionally, I noticed one check failure (pre-commit.ci-pr) and wanted to ask if you could help clarify the reason behind it. Apologies if this isn't the appropriate way to raise this, please do let me know the correct approach if needed.

Thanks again!

@Aniketsy Aniketsy force-pushed the bugfix-assert-categoricalindex-typeerror branch from de5b16b to 08739f2 Compare July 26, 2025 10:38
@Aniketsy
Copy link
Author

Checks fail

Hi @jorisvandenbossche, I ran pre-commit locally and all hooks passed. However, the GitHub checks are still showing a failure. Could you please advise if I’ve missed something?

@Aniketsy
Copy link
Author

Hi @mroeschke
When you have a moment, could you please review this PR? I've been working on resolving the check failure, but haven't been able to pinpoint the issue yet. Any insights or suggestions you could provide would be greatly appreciated.

Thank you!

Comment on lines 324 to 325
ci1 = CategoricalIndex(["a", "b", "c"], categories=["a", "b", "c"], ordered=False)
ci2 = CategoricalIndex(["a", "x", "c"], categories=["a", "b", "c"], ordered=False)
Copy link
Member

Choose a reason for hiding this comment

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

Can you test when 1 index is CategoricalIndex and the other is just 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.

Sorry I had meant an additional test in addition to the one you had

Copy link
Author

Choose a reason for hiding this comment

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

Please , let me know if , I need to add an additional test .

Comment on lines 328 to 329
if hasattr(left, "_internal_get_values") and hasattr(
right, "_internal_get_values"
Copy link
Member

Choose a reason for hiding this comment

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

Can you use isinstance checks to call _internal_get_values if the object is a CategoricalIndex?

Copy link
Author

Choose a reason for hiding this comment

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

Thankyou ! for correcting me . I have updated that

Copy link
Author

Choose a reason for hiding this comment

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

There is one check fail due to:
CategoricalIndex does not have an _internal_get_values() method.
So should i use .value or something else . Please suggest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants