BUG: Parameter check_flags is ignored in assert_frame_equal · Issue #45554 · pandas-dev/pandas (original) (raw)

Pandas version checks

Reproducible Example

import pandas as pd import pandas.testing as pdtest

df1 = pd.DataFrame([[1,2], [3,4]]) df1.flags.allows_duplicate_labels = False

df2 = pd.DataFrame([[1,2], [3,4]]) df2.flags.allows_duplicate_labels = True pdtest.assert_frame_equal(df1, df2, check_flags=False)

Issue Description

The above code raises the following error:

AssertionError                            Traceback (most recent call last)
Input In [6], in <module>
      4 df2 = pd.DataFrame([[1,2], [3,4]])
      5 df2.flags.allows_duplicate_labels = True
----> 7 pdtest.assert_frame_equal(df1, df2, check_flags=False)

    [... skipping hidden 1 frame]

File ~/Code/datafold-dev/.venv/lib/python3.8/site-packages/pandas/_testing/asserters.py:987, in assert_series_equal(left, right, check_dtype, check_index_type, check_series_type, check_less_precise, check_names, check_exact, check_datetimelike_compat, check_categorical, check_category_order, check_freq, check_flags, rtol, atol, obj, check_index)
    984     raise_assert_detail(obj, "Series length are different", msg1, msg2)
    986 if check_flags:
--> 987     assert left.flags == right.flags, f"{repr(left.flags)} != {repr(right.flags)}"
    989 if check_index:
    990     # GH #38183
    991     assert_index_equal(
    992         left.index,
    993         right.index,
   (...)
   1000         obj=f"{obj}.index",
   1001     )

AssertionError: <Flags(allows_duplicate_labels=False)> != <Flags(allows_duplicate_labels=True)>

Expected Behavior

I would expect that the flags in df1 and df2 are ignored. The documentation for the parameter says

check_flags : bool, default True
  Whether to check the `flags` attribute.

The above code should therefore not raise an error.

I believe the reason is that the check_flags parameter is not passed to assert_series_equal within assert_frame_equal

Installed Versions

INSTALLED VERSIONS

commit : bb1f651
python : 3.8.11.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-94-generic
Version : #106~18.04.1-Ubuntu SMP Fri Jan 7 07:23:53 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.4.0
numpy : 1.21.5
pytz : 2021.3
dateutil : 2.8.2
pip : 21.3.1
setuptools : 60.5.0
Cython : None
pytest : 6.2.4
hypothesis : None
sphinx : 4.3.2
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.3
IPython : 8.0.1
pandas_datareader: None
bs4 : 4.10.0
bottleneck : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.5.1
numba : None
numexpr : 2.8.1
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.7.3
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None