Skip to content

check_names=False parameter for pandas.util.testing.assert_frame_equal applies to index.names but not columns.names #19411

Closed
@willjbrown88

Description

@willjbrown88

edit by @TomAugspurger

The check_names docstring for pandas.util.testing.assert_frame_equal is unclear:

check_names : bool, default True
    Whether to check the Index names attribute.

This should clarify that both the index and columns names attribute are checked.


Code Sample, a copy-pastable example if possible

import pandas as pd
from pandas.util.testing import assert_frame_equal

df1 = pd.DataFrame({'A':[1.0]})
df2 = pd.DataFrame({'B':[1.0]})

assert_frame_equal(df1, df2, check_names=False)

""" will return:
In [7]: assert_frame_equal(df1, df2, check_names=False)
Traceback (most recent call last):

  File "<ipython-input-7-d273edeeb6af>", line 1, in <module>
    assert_frame_equal(df1, df2, check_names=False)

  File "<snipped>/lib/python3.5/site-packages/pandas/util/testing.py", line 1372, in assert_frame_equal
    obj='{obj}.columns'.format(obj=obj))

  File "<snipped>/lib/python3.5/site-packages/pandas/util/testing.py", line 927, in assert_index_equal
    obj=obj, lobj=left, robj=right)

  File "pandas/_libs/testing.pyx", line 59, in pandas._libs.testing.assert_almost_equal

  File "pandas/_libs/testing.pyx", line 173, in pandas._libs.testing.assert_almost_equal

  File "<snipped>/lib/python3.5/site-packages/pandas/util/testing.py", line 1093, in raise_assert_detail
    raise AssertionError(msg)

AssertionError: DataFrame.columns are different

DataFrame.columns values are different (100.0 %)
[left]:  Index(['A'], dtype='object')
[right]: Index(['B'], dtype='object')
"""

Problem description

When the parameter check_names=False is set for assert_frames_equal, the index and columns names should be ignored in the comparison, but an assertion error is still raised if the index or columns names are different. This is the same behaviour as when check_names=True (the default) is set, and the opposite of what I believe is intended.

Expected Output

The expected output for the case above should be nothing - a valid assertion.

Output of pd.show_versions()

In [8]: pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.5.4.final.0
python-bits: 64
OS: Linux
OS-release: 3.10.0-327.13.1.el7.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: en_GB.UTF-8

pandas: 0.22.0
pytest: 3.2.1
pip: 9.0.1
setuptools: 27.2.0
Cython: None
numpy: 1.13.1
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: 5.1.0
sphinx: 1.4.8
patsy: None
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.0.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions