Pandas DataFrame assertion ignores check_names=False parameter

37 views Asked by At

pandas.testing.assert_frame_equal throws an error when running this despite check_names=False:

import pandas as pd
left = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]})
# Note the second column is now 'c' instead of 'b'
right = pd.DataFrame({'a': [1, 2, 3], 'c': [4, 5, 6]})
pd.testing.assert_frame_equal(left, right, check_names=False)

This is the error:

Traceback (most recent call last):

  Cell In[36], line 4
    pd.testing.assert_frame_equal(left, right, check_names=False)

  File ~/venvs/base/lib/python3.10/site-packages/pandas/_testing/asserters.py:1240 in assert_frame_equal
    assert_index_equal(

  File ~/venvs/base/lib/python3.10/site-packages/pandas/_testing/asserters.py:326 in assert_index_equal
    _testing.assert_almost_equal(

  File testing.pyx:55 in pandas._libs.testing.assert_almost_equal

  File testing.pyx:173 in pandas._libs.testing.assert_almost_equal

  File ~/venvs/base/lib/python3.10/site-packages/pandas/_testing/asserters.py:614 in raise_assert_detail
    raise AssertionError(msg)

AssertionError: DataFrame.columns are different

DataFrame.columns values are different (50.0 %)
[left]:  Index(['a', 'b'], dtype='object')
[right]: Index(['a', 'c'], dtype='object')
At positional index 1, first diff: b != c

Versions (tried to use details to no avail)

commit : bdc79c1
python : 3.10.12.final.0
python-bits : 64
OS : Darwin
OS-release : 22.6.0
Version : Darwin Kernel Version 22.6.0: Mon Feb 19 19:48:53 PST 2024; root:xnu-8796.141.3.704.6~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : de_DE.UTF-8
LANG : de_DE.UTF-8
LOCALE : de_DE.UTF-8

pandas : 2.2.1
numpy : 1.23.5
pytz : 2023.3
dateutil : 2.8.2
setuptools : 69.0.2
pip : 24.0
Cython : None
pytest : None
hypothesis : None
sphinx : 6.1.3
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.14.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.2
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2023.9.2
gcsfs : None
matplotlib : 3.7.2
numba : 0.58.0
numexpr : None
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : 14.0.1
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.10.1
sqlalchemy : None
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : 2.4.1
pyqt5 : None
0

There are 0 answers