-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Fix obj arguments in assertions #59460
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 2 commits
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 |
---|---|---|
|
@@ -32,9 +32,9 @@ def test_index_equal_levels_mismatch(): | |
|
||
|
||
def test_index_equal_values_mismatch(check_exact): | ||
msg = """MultiIndex level \\[1\\] are different | ||
msg = """Index level \\[1\\] are different | ||
|
||
MultiIndex level \\[1\\] values are different \\(25\\.0 %\\) | ||
Index level \\[1\\] values are different \\(25\\.0 %\\) | ||
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. I'm not sure I really like this change. I think 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. I see. Just to be on the same page, have you got the opportunity to skim #59440? 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. Ok so I tried to make a compromise (09a1ae5), which in short is: root_obj = "MultiIndex" if obj == "Index" else obj
...
lobj = f"{root_obj} level [{level}]" I find that a little brittle, as it is based on the fact that about a hundred lines before there is ...So I tried harder (ad99297), which correspond to the current state of the PR. That is having the if obj is None:
obj = "MultiIndex" if isinstance(left, MultiIndex) else "Index" Thoughts? Better ideas? 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. Hello @mroeschke, have you got the chance to check this? Thanks! 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.
No disagreement that it is slightly clearer, but it bucks the otherwise consistent behavior of |
||
\\[left\\]: Index\\(\\[2, 2, 3, 4\\], dtype='int64'\\) | ||
\\[right\\]: Index\\(\\[1, 2, 3, 4\\], dtype='int64'\\)""" | ||
|
||
|
@@ -172,9 +172,9 @@ def test_index_equal_level_values_mismatch(check_exact, rtol): | |
idx2 = MultiIndex.from_tuples([("A", 1), ("A", 2), ("B", 3), ("B", 4)]) | ||
kwargs = {"check_exact": check_exact, "rtol": rtol} | ||
|
||
msg = """MultiIndex level \\[1\\] are different | ||
msg = """Index level \\[1\\] are different | ||
|
||
MultiIndex level \\[1\\] values are different \\(25\\.0 %\\) | ||
Index level \\[1\\] values are different \\(25\\.0 %\\) | ||
\\[left\\]: Index\\(\\[2, 2, 3, 4\\], dtype='int64'\\) | ||
\\[right\\]: Index\\(\\[1, 2, 3, 4\\], dtype='int64'\\)""" | ||
|
||
|
@@ -311,9 +311,7 @@ def test_assert_multi_index_dtype_check_categorical(check_categorical): | |
idx1 = MultiIndex.from_arrays([Categorical(np.array([1, 2], dtype=np.uint64))]) | ||
idx2 = MultiIndex.from_arrays([Categorical(np.array([1, 2], dtype=np.int64))]) | ||
if check_categorical: | ||
with pytest.raises( | ||
AssertionError, match=r"^MultiIndex level \[0\] are different" | ||
): | ||
with pytest.raises(AssertionError, match=r"^Index level \[0\] are different"): | ||
tm.assert_index_equal(idx1, idx2, check_categorical=check_categorical) | ||
else: | ||
tm.assert_index_equal(idx1, idx2, check_categorical=check_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.
Didn't manage to write a test for this (type seems to be already checked just above), which, given its comment, smells very corner-case-y. Probably it's better to stop the head-banging, unless you have ideas on a test case, of course