Skip to content

BUG: assert_index_equal does not raise error for check_categorical=False when comparing 2 CategoricalIndex objects #21092

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 14 commits into from
May 19, 2018

Conversation

alysivji
Copy link
Contributor

@alysivji alysivji commented May 16, 2018

  • tests added for check_categorical parameter in assert_series_equal
  • cleaned up assert_categorical_equal parameter order and docstring to match other functions (obj at the end)

Thanks to all maintainers who helped answer questions on Gitter during the informal PyCon sprint!

@pep8speaks
Copy link

pep8speaks commented May 16, 2018

Hello @alysivji! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on May 17, 2018 at 13:21 Hours UTC

@codecov
Copy link

codecov bot commented May 16, 2018

Codecov Report

Merging #21092 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #21092      +/-   ##
==========================================
+ Coverage   91.83%   91.84%   +<.01%     
==========================================
  Files         153      153              
  Lines       49495    49498       +3     
==========================================
+ Hits        45454    45459       +5     
+ Misses       4041     4039       -2
Flag Coverage Δ
#multiple 90.23% <100%> (ø) ⬆️
#single 41.88% <100%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/util/testing.py 84.81% <100%> (+0.21%) ⬆️
pandas/core/base.py 96.83% <0%> (ø) ⬆️
pandas/core/frame.py 97.23% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 501f041...86999e3. Read the comment docs.

@@ -76,7 +76,7 @@ Bug Fixes
Categorical
^^^^^^^^^^^

-
- Bug in :func:`pandas.util.testing.assert_index_equal` raised ``AssertionError`` if comparing two :class:`CategoricalIndex` objects when ``check_categorical=False`` (:issue:`19776`)
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be moved to 0.23.1 since it isn't an API breaking change.

@TomAugspurger TomAugspurger added this to the 0.23.1 milestone May 16, 2018
Copy link
Contributor

@TomAugspurger TomAugspurger left a comment

Choose a reason for hiding this comment

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

Just a couple minor things. LGTM otherwise.


Attribute "dtype" are different
\\[left\\]: CategoricalDtype\\(categories=\\[u?'a', u?'b'\\], ordered=False\\)
\\[right\\]: CategoricalDtype\\(categories=\\[u?'a', u?'b', u?'c'\\], ordered=False\\)""" # noqa
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a slight preference for avoiding the noqa if possible. Can you use a \ to escape the newline? Something like

        expected = """Attributes are different

Attribute "dtype" are different
\\[left\\]:  CategoricalDtype\\(categories=\\[u?'a', u?'b'\\], ordered=False\\)
\\[right\\]: CategoricalDtype\\(categories=\\[u?'a', u?'b', u?'c'\\], \
ordered=False\\)"""

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, didn't feel right to me either. I was wondering how to split lines.

Categorical
^^^^^^^^^^^

- Bug in :func:`pandas.util.testing.assert_index_equal` raised ``AssertionError`` if comparing two :class:`CategoricalIndex` objects when ``check_categorical=False`` (:issue:`19776`)
Copy link
Contributor

Choose a reason for hiding this comment

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

which raised AssertionError incorrectly, when comparing two ....

@@ -829,7 +833,8 @@ def _get_ilevel_values(index, level):
# get_level_values may change dtype
_check_types(left.levels[level], right.levels[level], obj=obj)

if check_exact:
run_exact_index_check = check_exact and check_categorical
Copy link
Contributor

Choose a reason for hiding this comment

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

you don't need a variable, just do the:

if checkexact and check_categorical:

check_dtype : bool, default True
Check that integer dtype of the codes are the same
obj : str, default 'Categorical'
Specify object name being compared, internally used to show appropriate
Copy link
Contributor

Choose a reason for hiding this comment

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

did you move this to make this consistent with other function orderings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, you got it. There is at least one more that can be made more consistent. @jreback should I add to this PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

sure

@jreback jreback added Categorical Categorical Data Type Needs Backport Testing pandas testing functions or related to the test suite labels May 17, 2018
@@ -1020,7 +1025,7 @@ def raise_assert_detail(obj, message, left, right, diff=None):

def assert_numpy_array_equal(left, right, strict_nan=False,
check_dtype=True, err_msg=None,
obj='numpy array', check_same=None):
check_same=None, obj='numpy array'):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

modified order of params to match other assert_* helper methods

@jreback jreback merged commit af2b609 into pandas-dev:master May 19, 2018
@jreback
Copy link
Contributor

jreback commented May 19, 2018

thanks @alysivji

jorisvandenbossche pushed a commit to jorisvandenbossche/pandas that referenced this pull request Jun 8, 2018
…lse when comparing 2 CategoricalIndex objects (pandas-dev#21092)

(cherry picked from commit af2b609)
jorisvandenbossche pushed a commit that referenced this pull request Jun 9, 2018
…lse when comparing 2 CategoricalIndex objects (#21092)

(cherry picked from commit af2b609)
david-liu-brattle-1 pushed a commit to david-liu-brattle-1/pandas that referenced this pull request Jun 18, 2018
@alysivji alysivji deleted the assert-cat-index branch June 17, 2024 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Categorical Categorical Data Type Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

assert_index_equal checks categories with check_categorical=False
5 participants