Skip to content

ENH: Show column name in assert_frame_equal #29218

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
12 changes: 6 additions & 6 deletions pandas/tests/util/test_assert_frame_equal.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ def test_frame_equal_columns_mismatch(obj_fixture):


def test_frame_equal_block_mismatch(by_blocks_fixture, obj_fixture):
msg = """{obj}\\.iloc\\[:, 1\\] are different
msg = """{obj}\\.iloc\\[:, 1\\] \\(column name="B"\\) are different

{obj}\\.iloc\\[:, 1\\] values are different \\(33\\.33333 %\\)
{obj}\\.iloc\\[:, 1\\] \\(column name="B"\\) values are different \\(33\\.33333 %\\)
\\[left\\]: \\[4, 5, 6\\]
\\[right\\]: \\[4, 5, 7\\]""".format(
obj=obj_fixture
Expand All @@ -202,18 +202,18 @@ def test_frame_equal_block_mismatch(by_blocks_fixture, obj_fixture):
(
DataFrame({"A": ["á", "à", "ä"], "E": ["é", "è", "ë"]}),
DataFrame({"A": ["á", "à", "ä"], "E": ["é", "è", "e̊"]}),
"""{obj}\\.iloc\\[:, 1\\] are different
"""{obj}\\.iloc\\[:, 1\\] \\(column name="E"\\) are different

{obj}\\.iloc\\[:, 1\\] values are different \\(33\\.33333 %\\)
{obj}\\.iloc\\[:, 1\\] \\(column name="E"\\) values are different \\(33\\.33333 %\\)
\\[left\\]: \\[é, è, ë\\]
\\[right\\]: \\[é, è, e̊\\]""",
),
(
DataFrame({"A": ["á", "à", "ä"], "E": ["é", "è", "ë"]}),
DataFrame({"A": ["a", "a", "a"], "E": ["e", "e", "e"]}),
"""{obj}\\.iloc\\[:, 0\\] are different
"""{obj}\\.iloc\\[:, 0\\] \\(column name="A"\\) are different

{obj}\\.iloc\\[:, 0\\] values are different \\(100\\.0 %\\)
{obj}\\.iloc\\[:, 0\\] \\(column name="A"\\) values are different \\(100\\.0 %\\)
\\[left\\]: \\[á, à, ä\\]
\\[right\\]: \\[a, a, a\\]""",
),
Expand Down
6 changes: 4 additions & 2 deletions pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,7 @@ def assert_frame_equal(
>>> assert_frame_equal(df1, df2)
Traceback (most recent call last):
...
AssertionError: Attributes of DataFrame.iloc[:, 1] are different
AssertionError: Attributes of DataFrame.iloc[:, 1] (column name="b") are different

Attribute "dtype" are different
[left]: int64
Expand Down Expand Up @@ -1400,7 +1400,9 @@ def assert_frame_equal(
check_names=check_names,
check_datetimelike_compat=check_datetimelike_compat,
check_categorical=check_categorical,
obj="{obj}.iloc[:, {idx}]".format(obj=obj, idx=i),
obj='{obj}.iloc[:, {idx}] (column name="{col}")'.format(
Copy link
Member

Choose a reason for hiding this comment

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

If you wanted to could just use f-strings to make this even more compact

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are new in 3.6. Is anything older not supported anymore by pandas?

Copy link
Contributor

Choose a reason for hiding this comment

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

no we just dropped 3.5

obj=obj, idx=i, col=col
),
)


Expand Down