pandas-dev / pandas

Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
https://pandas.pydata.org
BSD 3-Clause "New" or "Revised" License
43.6k stars 17.9k forks source link

BUG: `equals` method failed for nested `Series`/`DataFrame` #43008

Open ChiQiao opened 3 years ago

ChiQiao commented 3 years ago

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

Code Sample, a copy-pastable example

inner_foo = pd.Series(dtype=float)
inner_bar = inner_foo.copy()
foo = pd.Series({0: inner_foo})
bar = pd.Series({0: inner_bar})
foo.equals(bar)

Problem description

Get an exception: ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). This issue applies to both Series and DataFrame, that equals method failed if there is a nested Series or DataFrame. Note that pd.testing.assert_series_equal(foo, bar) still works.

Expected Output

True

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit : c7f7443c1bad8262358114d5e88cd9c8a308e8aa python : 3.7.11.final.0 python-bits : 64 OS : Windows OS-release : 10 Version : 10.0.19041 machine : AMD64 processor : Intel64 Family 6 Model 142 Stepping 10, GenuineIntel byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : None.None pandas : 1.3.1 numpy : 1.20.3 pytz : 2021.1 dateutil : 2.8.2 pip : 21.2.2 setuptools : 52.0.0.post20210125 Cython : 0.29.24 pytest : 6.1.2 hypothesis : 6.14.1 sphinx : 4.0.2 blosc : None feather : None xlsxwriter : 1.4.4 lxml.etree : 4.6.3 html5lib : 1.1 pymysql : 1.0.2 psycopg2 : None jinja2 : 3.0.1 IPython : 7.22.0 pandas_datareader: None bs4 : 4.9.3 bottleneck : 1.3.2 fsspec : 2021.07.0 fastparquet : None gcsfs : None matplotlib : 3.4.2 numexpr : 2.7.3 odfpy : None openpyxl : 3.0.7 pandas_gbq : None pyarrow : 3.0.0 pyxlsb : None s3fs : 0.4.2 scipy : 1.6.2 sqlalchemy : 1.4.22 tables : 3.6.1 tabulate : 0.8.9 xarray : 0.19.0 xlrd : 2.0.1 xlwt : 1.3.0 numba : 0.53.0
rickspark4 commented 3 years ago

what do you mean by nested series?

rickspark4 commented 3 years ago

btw I am new to open source😅😅

ChiQiao commented 3 years ago

what do you mean by nested series?

For the example above, inner_foo is a Series nested in foo (which is also a Series).