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

BUG: Series.equals fails when comparing numpy arrays to scalars #35267

Closed
3 tasks done
avinashpancham opened this issue Jul 13, 2020 · 6 comments · Fixed by #36161
Closed
3 tasks done

BUG: Series.equals fails when comparing numpy arrays to scalars #35267

avinashpancham opened this issue Jul 13, 2020 · 6 comments · Fixed by #36161
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations
Milestone

Comments

@avinashpancham
Copy link
Contributor

  • 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.


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
import numpy as np

arr = np.array([1, 2])
s1 = pd.Series([arr, arr])
s2 = s1.copy()

s1[1] = 9
s1.equals(s2) # This throws a ValueError

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Problem description

Series.equals operation fails when comparing two Series that at the same position respectively have a single value and a list. Pandas then throws a ValueError since it cannot compare a single value to a list.

Related issues #20676 and #35237

Expected Output

False, since the two series are not equal

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 9827ce0
python : 3.8.3.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 : None
LOCALE : None.UTF-8

pandas : 1.1.0.dev0+2088.g9827ce00f
numpy : 1.18.5
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 49.2.0.post20200712
Cython : 0.29.21
pytest : 5.4.3
hypothesis : 5.19.1
sphinx : 3.1.1
blosc : None
feather : None
xlsxwriter : 1.2.9
lxml.etree : 4.5.2
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.16.1
pandas_datareader: None
bs4 : 4.9.1
bottleneck : 1.3.2
fsspec : 0.7.4
fastparquet : 0.4.0
gcsfs : 0.6.2
matplotlib : 3.2.2
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.4
pandas_gbq : None
pyarrow : 0.17.1
pytables : None
pyxlsb : None
s3fs : 0.4.2
scipy : 1.5.0
sqlalchemy : 1.3.18
tables : 3.6.1
tabulate : 0.8.7
xarray : 0.16.0
xlrd : 1.2.0
xlwt : 1.3.0
numba : 0.50.1

@avinashpancham avinashpancham added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 13, 2020
@avinashpancham
Copy link
Contributor Author

If we decide to go ahead and fix this bug then I would like to contribute. I'm still a beginner, so if someone can point me in the right direction it would be very helpful!

@Dr-Irv
Copy link
Contributor

Dr-Irv commented Jul 14, 2020

@avinashpancham can you put a better title on this issue?

@avinashpancham avinashpancham changed the title BUG: BUG: Series.equals fails when comparing iterables to non-iterables Jul 14, 2020
@avinashpancham
Copy link
Contributor Author

Sorry, saw that I forgot to edit the title. Updated it.

@TomAugspurger TomAugspurger removed the Needs Triage Issue that has not been reviewed by a pandas team member label Sep 4, 2020
@TomAugspurger
Copy link
Contributor

This looks lie a bug, but I'm not sure where best to fix it. Investigation would be welcome.

@TomAugspurger TomAugspurger added the Numeric Operations Arithmetic, Comparison, and Logical operations label Sep 4, 2020
@avinashpancham
Copy link
Contributor Author

I can have a look at it this weekend

@avinashpancham
Copy link
Contributor Author

avinashpancham commented Sep 6, 2020

Extending array_equivalent_object in _libs/lib.pyx seemed like the best way to solve this issue. What do you think?

@avinashpancham avinashpancham changed the title BUG: Series.equals fails when comparing iterables to non-iterables BUG: Series.equals fails when comparing numpy arrays to scalars Sep 10, 2020
@jreback jreback added this to the 1.2 milestone Sep 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants