-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2db2c26
fix categorical check
alysivji 7cfa957
Add tests for index and series
alysivji 7606152
clean up assert_categoricals_eq to match others
alysivji f61e538
Rearrange order of docstring to match params
alysivji 53ac4a4
Refactor comment into boolean check for readability
alysivji 25d9fe6
Add whatsnew entry
alysivji fb24ed5
Fix grammar
alysivji 1476149
Fix pep 8
alysivji 0de8800
explicitly state unicode string
alysivji d5ab039
properly fix unicode string failures
alysivji dba649f
Code review suggestions
alysivji 97f300f
Rearrange order of assert_numpy_array_equals to match other assert_*
alysivji 2fb09fe
Refactor boolean var into if and add comment
alysivji 86999e3
Improve description in whatsnew
alysivji File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -778,8 +778,12 @@ def assert_index_equal(left, right, exact='equiv', check_names=True, | |
|
||
def _check_types(l, r, obj='Index'): | ||
if exact: | ||
assert_class_equal(left, right, exact=exact, obj=obj) | ||
assert_attr_equal('dtype', l, r, obj=obj) | ||
assert_class_equal(l, r, exact=exact, obj=obj) | ||
|
||
# Skip exact dtype checking when `check_categorical` is False | ||
if check_categorical: | ||
assert_attr_equal('dtype', l, r, obj=obj) | ||
|
||
# allow string-like to have different inferred_types | ||
if l.inferred_type in ('string', 'unicode'): | ||
assert r.inferred_type in ('string', 'unicode') | ||
|
@@ -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: | ||
# skip exact index checking when `check_categorical` is False | ||
if check_exact and check_categorical: | ||
if not left.equals(right): | ||
diff = np.sum((left.values != right.values) | ||
.astype(int)) * 100.0 / len(left) | ||
|
@@ -950,23 +955,23 @@ def is_sorted(seq): | |
|
||
|
||
def assert_categorical_equal(left, right, check_dtype=True, | ||
obj='Categorical', check_category_order=True): | ||
check_category_order=True, obj='Categorical'): | ||
"""Test that Categoricals are equivalent. | ||
|
||
Parameters | ||
---------- | ||
left, right : Categorical | ||
Categoricals to compare | ||
left : Categorical | ||
right : 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 | ||
assertion message | ||
check_category_order : bool, default True | ||
Whether the order of the categories should be compared, which | ||
implies identical integer codes. If False, only the resulting | ||
values are compared. The ordered attribute is | ||
checked regardless. | ||
obj : str, default 'Categorical' | ||
Specify object name being compared, internally used to show appropriate | ||
assertion message | ||
""" | ||
_check_isinstance(left, right, Categorical) | ||
|
||
|
@@ -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'): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. modified order of params to match other |
||
""" Checks that 'np.ndarray' is equivalent | ||
|
||
Parameters | ||
|
@@ -1033,11 +1038,11 @@ def assert_numpy_array_equal(left, right, strict_nan=False, | |
check dtype if both a and b are np.ndarray | ||
err_msg : str, default None | ||
If provided, used as assertion message | ||
check_same : None|'copy'|'same', default None | ||
Ensure left and right refer/do not refer to the same memory area | ||
obj : str, default 'numpy array' | ||
Specify object name being compared, internally used to show appropriate | ||
assertion message | ||
check_same : None|'copy'|'same', default None | ||
Ensure left and right refer/do not refer to the same memory area | ||
""" | ||
|
||
# instance validation | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure