Skip to content

DOC: Mention Index.equals takes into account order of arguments #33285

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

Closed
3 tasks done
jlandercy opened this issue Apr 4, 2020 · 3 comments · Fixed by #33289
Closed
3 tasks done

DOC: Mention Index.equals takes into account order of arguments #33285

jlandercy opened this issue Apr 4, 2020 · 3 comments · Fixed by #33289
Assignees
Labels
Milestone

Comments

@jlandercy
Copy link

  • 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

import pandas as pd
pd.Index(['10607', '6574', '6621', '99917']).equals(pd.Index(['99917', '10607', '6574', '6621'])) # False
set(['10607', '6574', '6621', '99917']) == set(['99917', '10607', '6574', '6621']) # True

Problem description

I have seen #13708, but according to documentation:

Determine if two Index objects contain the same elements.

Should it return True instead?

Reading how the function is implemented:

return array_equivalent(
com.values_from_object(self), com.values_from_object(other)
)

It relies on:

Examples
--------
>>> array_equivalent(
... np.array([1, 2, np.nan]),
... np.array([1, 2, np.nan]))
True
>>> array_equivalent(
... np.array([1, np.nan, 2]),
... np.array([1, 2, np.nan]))
False
"""

Which is indeed strict and do take order into account.

Expected Output

As I understand the equality of index is about having the same elements. It is not required the elements having the same order. I have the feeling that once pandas worked this way (maybe before v0.23).

What is the intended way ? Maybe the documentation should be a bit more explicit about this comparison. If you indicate me where I can update the doc, I will be glad to edit it.

Output of pd.show_versions()

commit : None
python : 3.6.9.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-91-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.0.3
numpy : 1.18.2
pytz : 2019.3
dateutil : 2.8.1
pip : 9.0.1
setuptools : 46.1.3
Cython : 0.29.14
pytest : 5.3.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 1.1.8
lxml.etree : 4.3.4
html5lib : 0.999999999
pymysql : None
psycopg2 : 2.8.4 (dt dec pq3 ext lo64)
jinja2 : 2.11.1
IPython : 7.13.0
pandas_datareader: None
bs4 : 4.7.1
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.3.4
matplotlib : 3.2.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 0.13.0
pytables : None
pytest : 5.3.2
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : 1.3.15
tables : None
tabulate : 0.8.3
xarray : None
xlrd : 1.2.0
xlwt : 1.3.0
xlsxwriter : 1.1.8
numba : None

@jlandercy jlandercy added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 4, 2020
@dsaxton
Copy link
Member

dsaxton commented Apr 4, 2020

I think that like the other issue this is really a problem with the documentation and not an actual bug (the method tests for equivalence and not just having the same elements as you point out). I would think that a PR to fix the documentation makes sense?

@mroeschke
Copy link
Member

Agreed. The documentation can be clarified to mention that order is significant.

@mroeschke mroeschke removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 4, 2020
@mroeschke mroeschke changed the title BUG: Index holding exaclty same values are not equals DOC: Mention Index.equals takes into account order of arguments Apr 4, 2020
@mroeschke mroeschke added the Docs label Apr 4, 2020
@ShaharNaveh
Copy link
Member

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants