BUG: pd.testing.assert_frame_equal(..., check_exact=True) raises assertion error if any columns are not numeric · Issue #35446 · pandas-dev/pandas (original) (raw)


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

import pandas as pd a = pd.DataFrame({"a": list("bc"), "b": [1, 2]}) pd.testing.assert_frame_equal(a, a.copy(), check_exact=True)

...: a = pd.DataFrame({"a": list("bc"), "b": [1, 2]}) ...: pd.testing.assert_frame_equal(a, a.copy(), check_exact=True)

AssertionError Traceback (most recent call last) in 1 import pandas as pd 2 a = pd.DataFrame({"a": list("bc"), "b": [1, 2]}) ----> 3 pd.testing.assert_frame_equal(a, a.copy(), check_exact=True)

[... skipping hidden 2 frame]

AssertionError: check_exact may only be used with numeric Series

Problem description

Previously, the example above would not have thrown an error. It makes it a less useful function if I have to start subdividing dataframes by types just to check that they are equal. Presumably check_exact should either have no effect if called on a non-numeric Series or assert_frame_equal should not pass check_exact=True if the series to be compared isn't numeric.

It looks like this was introduced recently, in 08c6597

Expected Output

I expected it to work like it did previously, and not throw an error. Here's an example of test failures this is causing.

Output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit           : d9fff2792bf16178d4e450fe7384244e50635733
python           : 3.8.5.final.0
python-bits      : 64
OS               : Darwin
OS-release       : 19.5.0
Version          : Darwin Kernel Version 19.5.0: Tue May 26 20:41:44 PDT 2020; root:xnu-6153.121.2~2/RELEASE_X86_64
machine          : x86_64
processor        : i386
byteorder        : little
LC_ALL           : None
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 1.1.0
numpy            : 1.19.0
pytz             : 2020.1
dateutil         : 2.8.1
pip              : 20.1.1
setuptools       : 49.2.0
Cython           : None
pytest           : 5.4.3
hypothesis       : None
sphinx           : 3.1.2
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : 2.11.2
IPython          : 7.16.1
pandas_datareader: None
bs4              : None
bottleneck       : None
fsspec           : 0.7.4
fastparquet      : None
gcsfs            : None
matplotlib       : 3.3.0
numexpr          : 2.7.1
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : 0.17.1
pytables         : None
pyxlsb           : None
s3fs             : None
scipy            : 1.5.1
sqlalchemy       : 1.3.18
tables           : 3.6.1
tabulate         : None
xarray           : 0.16.0
xlrd             : 1.2.0
xlwt             : None
numba            : 0.50.1