-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: Fix output of assert_frame_equal if indexes differ and check_like=True #37479
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 all commits
a946334
2157ac7
20d67a8
25066f6
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 |
---|---|---|
|
@@ -667,6 +667,7 @@ def assert_index_equal( | |
check_less_precise: Union[bool, int] = no_default, | ||
check_exact: bool = True, | ||
check_categorical: bool = True, | ||
check_order: bool = True, | ||
rtol: float = 1.0e-5, | ||
atol: float = 1.0e-8, | ||
obj: str = "Index", | ||
|
@@ -696,6 +697,12 @@ def assert_index_equal( | |
Whether to compare number exactly. | ||
check_categorical : bool, default True | ||
Whether to compare internal Categorical exactly. | ||
check_order : bool, default True | ||
Whether to compare the order of index entries as well as their values. | ||
If True, both indexes must contain the same elements, in the same order. | ||
If False, both indexes must contain the same elements, but in any order. | ||
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. can you add a versionadded tag 1.2 here 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. Oh, that's annoying, sorry. |
||
|
||
.. versionadded:: 1.2.0 | ||
rtol : float, default 1e-5 | ||
Relative tolerance. Only used when check_exact is False. | ||
|
||
|
@@ -762,6 +769,11 @@ def _get_ilevel_values(index, level): | |
msg3 = f"{len(right)}, {right}" | ||
raise_assert_detail(obj, msg1, msg2, msg3) | ||
|
||
# If order doesn't matter then sort the index entries | ||
if not check_order: | ||
left = left.sort_values() | ||
right = right.sort_values() | ||
|
||
# MultiIndex special comparison for little-friendly error messages | ||
if left.nlevels > 1: | ||
left = cast(MultiIndex, left) | ||
|
@@ -1582,9 +1594,6 @@ def assert_frame_equal( | |
obj, f"{obj} shape mismatch", f"{repr(left.shape)}", f"{repr(right.shape)}" | ||
) | ||
|
||
if check_like: | ||
left, right = left.reindex_like(right), right | ||
|
||
if check_flags: | ||
assert left.flags == right.flags, f"{repr(left.flags)} != {repr(right.flags)}" | ||
|
||
|
@@ -1596,6 +1605,7 @@ def assert_frame_equal( | |
check_names=check_names, | ||
check_exact=check_exact, | ||
check_categorical=check_categorical, | ||
check_order=not check_like, | ||
rtol=rtol, | ||
atol=atol, | ||
obj=f"{obj}.index", | ||
|
@@ -1609,11 +1619,15 @@ def assert_frame_equal( | |
check_names=check_names, | ||
check_exact=check_exact, | ||
check_categorical=check_categorical, | ||
check_order=not check_like, | ||
rtol=rtol, | ||
atol=atol, | ||
obj=f"{obj}.columns", | ||
) | ||
|
||
if check_like: | ||
left, right = left.reindex_like(right), right | ||
|
||
# compare by blocks | ||
if by_blocks: | ||
rblocks = right._to_dict_of_blocks() | ||
|
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.
Probably it is necessary to have the new parameter added to the very end of this function signature in order not to break any user's code, which for some reason use positional arguments.
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.
Thanks for the feedback.
I debated that and it looked like the
rtol
andatol
params had been added before the (older)obj
param, so I decided to putcheck_order
with the other check params. That said,obj
is not something that most user code would pass so perhaps the comparrison doesn't hold.Happy to move the parameter.
I also just noticed that I forgot to add a
versionadded
tag (will do).