-
-
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
Changes from 11 commits
2db2c26
7cfa957
7606152
f61e538
53ac4a4
25d9fe6
fb24ed5
1476149
0de8800
d5ab039
dba649f
97f300f
2fb09fe
86999e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 with `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: | ||
run_exact_index_check = check_exact and check_categorical | ||
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. you don't need a variable, just do the:
|
||
if run_exact_index_check: | ||
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 | ||
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. 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. sure |
||
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) | ||
|
||
|
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.
which raised
AssertionError
incorrectly, when comparing two ....