Skip to content

BUG: Regression in assert_frame_equal when using check_like #39739

Closed
@galipremsagar

Description

@galipremsagar
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample, a copy-pastable example

In 1.2.1:

>>> import pandas as pd
>>> one = pd.Index([], dtype='object')
>>> two = pd.RangeIndex(start=0, stop=0, step=1)
>>> df_one = pd.DataFrame(index=one)
>>> df_two = pd.DataFrame(index=two)
>>> pd.testing.assert_frame_equal(df_one, df_two, check_like=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/nvme/0/pgali/envs/cudfdev/lib/python3.7/site-packages/pandas/_testing.py", line 1655, in assert_frame_equal
    obj=f"{obj}.index",
  File "/nvme/0/pgali/envs/cudfdev/lib/python3.7/site-packages/pandas/_testing.py", line 773, in assert_index_equal
    _check_types(left, right, obj=obj)
  File "/nvme/0/pgali/envs/cudfdev/lib/python3.7/site-packages/pandas/_testing.py", line 740, in _check_types
    assert_class_equal(left, right, exact=exact, obj=obj)
  File "/nvme/0/pgali/envs/cudfdev/lib/python3.7/site-packages/pandas/_testing.py", line 868, in assert_class_equal
    raise_assert_detail(obj, msg, repr_class(left), repr_class(right))
  File "/nvme/0/pgali/envs/cudfdev/lib/python3.7/site-packages/pandas/_testing.py", line 1073, in raise_assert_detail
    raise AssertionError(msg)
AssertionError: DataFrame.index are different

DataFrame.index classes are not equivalent
[left]:  Index([], dtype='object')
[right]: RangeIndex(start=0, stop=0, step=1)

In 1.1.5:

>>> import pandas as pd
>>> one = pd.Index([], dtype='object')
>>> two = pd.RangeIndex(start=0, stop=0, step=1)
>>> df_one = pd.DataFrame(index=one)
>>> df_two = pd.DataFrame(index=two)
>>> pd.testing.assert_frame_equal(df_one, df_two, check_like=True)

Problem description

Upto 1.1.5, both df_one and df_two were considered to be same dataframe when check_like=True, but in latest pandas this is broken.

Expected Output

>>> pd.testing.assert_frame_equal(df_one, df_two, check_like=True)

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 9d598a5
python : 3.7.9.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-76-generic
Version : #86-Ubuntu SMP Fri Jan 17 17:24:28 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.2.1
numpy : 1.19.5
pytz : 2021.1
dateutil : 2.8.1
pip : 21.0.1
setuptools : 49.6.0.post20210108
Cython : 0.29.21
pytest : 6.2.2
hypothesis : 6.1.1
sphinx : 3.4.3
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.20.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 0.8.5
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 1.0.1
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : 0.52.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Testingpandas testing functions or related to the test suite

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions