From f65a3a3ed548ca4d1839f792251a137392fb7bde Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Sat, 4 Apr 2020 22:13:25 +0300 Subject: [PATCH 1/5] DOC: Improved doc for `Index.equals` --- pandas/core/indexes/base.py | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 5fec68d257167..ec85d36da81bd 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -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 + + >>> idx2 = pd.Index(["1", "2", "3"]) + >>> idx2 + Index(['1', '2', '3'], dtype='object') + + >>> idx1.equals(idx2) + False + + The oreder is also been compared + + >>> 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 From 05f821c49700089502e10428965181d66c33d5b4 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Sun, 5 Apr 2020 16:57:08 +0300 Subject: [PATCH 2/5] Grammer XREF: https://github.com/pandas-dev/pandas/pull/33289#discussion_r403509327 https://github.com/pandas-dev/pandas/pull/33289#discussion_r403509363 --- pandas/core/indexes/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index ec85d36da81bd..306b8dbb52f48 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -4211,7 +4211,7 @@ def equals(self, other: Any) -> bool: >>> idx1.equals(pd.Index([1, 2, 3])) True - The dtype is been compared as well + The dtype is compared as well >>> idx2 = pd.Index(["1", "2", "3"]) >>> idx2 @@ -4220,7 +4220,7 @@ def equals(self, other: Any) -> bool: >>> idx1.equals(idx2) False - The oreder is also been compared + The oreder is also compared >>> ascending_idx = pd.Index([1, 2, 3]) >>> ascending_idx From bb6997c1c6f25721bcb03ad1a73c8ac457964277 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Sun, 5 Apr 2020 17:03:46 +0300 Subject: [PATCH 3/5] Added parameters sections, and a second peragraph XREF: https://github.com/pandas-dev/pandas/pull/33289#pullrequestreview-387790007 https://github.com/pandas-dev/pandas/pull/33289#discussion_r403662373 --- pandas/core/indexes/base.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 306b8dbb52f48..db15c58c5e943 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -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 ------- From 8028b7a4e908153aa1b396dc39eaf4cb0216eb7a Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Sun, 5 Apr 2020 17:18:38 +0300 Subject: [PATCH 4/5] Fix examples --- pandas/core/indexes/base.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index db15c58c5e943..0d6ebbdc7b0ed 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -4221,7 +4221,7 @@ def equals(self, other: Any) -> bool: >>> idx1.equals(pd.Index([1, 2, 3])) True - The dtype is compared as well + The elements inside are compared >>> idx2 = pd.Index(["1", "2", "3"]) >>> idx2 @@ -4230,7 +4230,7 @@ def equals(self, other: Any) -> bool: >>> idx1.equals(idx2) False - The oreder is also compared + The oreder is compared >>> ascending_idx = pd.Index([1, 2, 3]) >>> ascending_idx @@ -4240,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 From 70ce83d3247a0dd2a76b3a5106fc65edfcc17e09 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <50263213+MomIsBestFriend@users.noreply.github.com> Date: Mon, 6 Apr 2020 11:28:46 +0300 Subject: [PATCH 5/5] Update pandas/core/indexes/base.py Co-Authored-By: Joris Van den Bossche --- pandas/core/indexes/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 0d6ebbdc7b0ed..9a254a499ad82 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -4199,8 +4199,8 @@ def equals(self, other: Any) -> bool: The things that are being compared are: - * The elements inside the Index object. - * The order of the elements inside the Index object. + * The elements inside the Index object. + * The order of the elements inside the Index object. Parameters ----------