Skip to content

DOC: Improved doc for Index.equals #33289

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

Merged
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4195,7 +4195,17 @@ def putmask(self, mask, value):

def equals(self, other: Any) -> bool:
"""
Determine if two Index objects contain the same elements with the same order.
Determine if two Index object are equal.

The things that are being compared are:

* The elements inside the Index object.
* The order of the elements inside the Index object.

Parameters
----------
other : Any
The other object to compare against.

Returns
-------
Expand All @@ -4211,7 +4221,7 @@ def equals(self, other: Any) -> bool:
>>> idx1.equals(pd.Index([1, 2, 3]))
True

The dtype is been compared as well
The elements inside are compared

>>> idx2 = pd.Index(["1", "2", "3"])
>>> idx2
Expand All @@ -4220,7 +4230,7 @@ def equals(self, other: Any) -> bool:
>>> idx1.equals(idx2)
False

The oreder is also been compared
The oreder is compared

>>> ascending_idx = pd.Index([1, 2, 3])
>>> ascending_idx
Expand All @@ -4230,6 +4240,17 @@ def equals(self, other: Any) -> bool:
Int64Index([3, 2, 1], dtype='int64')
>>> ascending_idx.equals(descending_idx)
False

The dtype is *not* compared

>>> int64_idx = pd.Int64Index([1, 2, 3])
>>> int64_idx
Int64Index([1, 2, 3], dtype='int64')
>>> uint64_idx = pd.UInt64Index([1, 2, 3])
>>> uint64_idx
UInt64Index([1, 2, 3], dtype='uint64')
>>> int64_idx.equals(uint64_idx)
True
"""
if self.is_(other):
return True
Expand Down