-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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
Changes from 1 commit
f65a3a3
ab25939
05f821c
bb6997c
8028b7a
70ce83d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4193,15 +4193,43 @@ def putmask(self, mask, value): | |
# coerces to object | ||
return self.astype(object).putmask(mask, value) | ||
|
||
def equals(self, other) -> bool: | ||
def equals(self, other: Any) -> bool: | ||
""" | ||
Determine if two Index objects contain the same elements. | ||
Determine if two Index objects contain the same elements with the same order. | ||
|
||
Returns | ||
------- | ||
bool | ||
True if "other" is an Index and it has the same elements as calling | ||
index; False otherwise. | ||
True if "other" is an Index and it has the same elements and order | ||
as the calling index; False otherwise. | ||
|
||
Examples | ||
-------- | ||
>>> idx1 = pd.Index([1, 2, 3]) | ||
>>> idx1 | ||
Int64Index([1, 2, 3], dtype='int64') | ||
>>> idx1.equals(pd.Index([1, 2, 3])) | ||
True | ||
|
||
The dtype is been compared as well | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The dtype is actually not compared:
(in your example here, the values are not equal as a string is not equal to an integer) |
||
|
||
>>> idx2 = pd.Index(["1", "2", "3"]) | ||
>>> idx2 | ||
Index(['1', '2', '3'], dtype='object') | ||
|
||
>>> idx1.equals(idx2) | ||
False | ||
|
||
The oreder is also been compared | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
>>> ascending_idx = pd.Index([1, 2, 3]) | ||
>>> ascending_idx | ||
Int64Index([1, 2, 3], dtype='int64') | ||
>>> descending_idx = pd.Index([3, 2, 1]) | ||
>>> descending_idx | ||
Int64Index([3, 2, 1], dtype='int64') | ||
>>> ascending_idx.equals(descending_idx) | ||
False | ||
""" | ||
if self.is_(other): | ||
return True | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we could also simplify "... contain the same elements with the same order" to "... are equal" ?
We can in a second paragraph detail on what is considered as equal