Skip to content
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

assert_frame_equal: "AssertionError: Attributes are different" is un-informative for DataFrames #28991

Closed
moi90 opened this issue Oct 15, 2019 · 0 comments · Fixed by #28993
Closed
Labels
Testing pandas testing functions or related to the test suite
Milestone

Comments

@moi90
Copy link
Contributor

moi90 commented Oct 15, 2019

Example from the docstring of assert_frame_equal

>>> from pandas.util.testing import assert_frame_equal
>>> df1 = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})
>>> df2 = pd.DataFrame({'a': [1, 2], 'b': [3.0, 4.0]})
>>> assert_frame_equal(df1, df2)
Traceback (most recent call last):
AssertionError: Attributes are different
...
Attribute "dtype" are different
[left]:  int64
[right]: float64

Problem description

The AssertionError is un-informative in that it does not state the column for which the error happens.

Expected Output

Something like:

AssertionError: Attributes of "DataFrame.iloc[:, 1]" are different
...
Attribute "dtype" are different.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.6.7.final.0
python-bits : 64
OS : Linux
OS-release : 5.0.0-31-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : de_DE.UTF-8
LOCALE : de_DE.UTF-8

pandas : 0.25.0
numpy : 1.17.2
pytz : 2019.3
dateutil : 2.8.0
pip : 19.2.3
setuptools : 41.4.0
Cython : 0.29.13
pytest : 5.2.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.8.3 (dt dec pq3 ext lo64)
jinja2 : 2.10.3
IPython : 7.7.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : 2.7.0
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : 1.3.1
sqlalchemy : 1.3.6
tables : 3.5.2
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None

Remedy

  • assert_frame_equal passes obj="{obj}.iloc[:, {idx}]".format(obj=obj, idx=i) to assert_series_equal
  • assert_series_equal should pass obj=Attributes of "{obj}".format(obj=obj) to assert_attr_equal
@jreback jreback added the Testing pandas testing functions or related to the test suite label Oct 16, 2019
@jreback jreback added this to the 1.0 milestone Oct 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants