From 93336eb467a57df0a953e05c0dec3b9d99824007 Mon Sep 17 00:00:00 2001 From: Raisa Dzhamtyrova Date: Thu, 27 Feb 2020 22:15:24 +0000 Subject: [PATCH 1/3] DOC: add examples to the method MultiIndex.is_lexsorted() --- pandas/core/indexes/multi.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 4bd462e83a5bc..e3744ef7aca67 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1625,6 +1625,19 @@ def is_lexsorted(self) -> bool: Returns ------- bool + + Examples + -------- + >>> pd.MultiIndex.from_arrays([[0, 1, 1], ['a', 'b', 'c']]).is_lexsorted() + True + >>> pd.MultiIndex.from_arrays([[0, 1, 1], ['a', 'c', 'b']]).is_lexsorted() + False + >>> pd.MultiIndex.from_arrays([['a', 'a', 'b', 'b'], + ... ['aa', 'bb', 'aa', 'bb']]).is_lexsorted() + True + >>> pd.MultiIndex.from_arrays([['a', 'a', 'b', 'b'], + ... ['bb', 'aa', 'aa', 'bb']]).is_lexsorted() + False """ return self.lexsort_depth == self.nlevels From bd442f919b95410ffd9967d3023298ded8f5f739 Mon Sep 17 00:00:00 2001 From: Raisa Dzhamtyrova Date: Tue, 3 Mar 2020 14:17:15 +0000 Subject: [PATCH 2/3] add an example with explanation --- pandas/core/indexes/multi.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index e3744ef7aca67..c2632148c81c6 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1628,6 +1628,16 @@ def is_lexsorted(self) -> bool: Examples -------- + >>> pd.MultiIndex.from_arrays([['a', 'b', 'c'], ['d', 'e', 'f']]).is_lexsorted() + True + >>> pd.MultiIndex.from_arrays([['a', 'b', 'c'], ['d', 'f', 'e']]).is_lexsorted() + True + + In the above examples, the first level of MultiIndex is sorted because a>> pd.MultiIndex.from_arrays([[0, 1, 1], ['a', 'b', 'c']]).is_lexsorted() True >>> pd.MultiIndex.from_arrays([[0, 1, 1], ['a', 'c', 'b']]).is_lexsorted() From e957a3709aaa1e74bf15e38a1a0693e4765d7fff Mon Sep 17 00:00:00 2001 From: Raisa Dzhamtyrova Date: Sun, 15 Mar 2020 10:32:18 +0000 Subject: [PATCH 3/3] put the explanation above the examples --- pandas/core/indexes/multi.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index c2632148c81c6..d6187819c2a2e 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1628,15 +1628,16 @@ def is_lexsorted(self) -> bool: Examples -------- + In the below examples, the first level of the MultiIndex is sorted because + a>> pd.MultiIndex.from_arrays([['a', 'b', 'c'], ['d', 'e', 'f']]).is_lexsorted() True >>> pd.MultiIndex.from_arrays([['a', 'b', 'c'], ['d', 'f', 'e']]).is_lexsorted() True - In the above examples, the first level of MultiIndex is sorted because a>> pd.MultiIndex.from_arrays([[0, 1, 1], ['a', 'b', 'c']]).is_lexsorted() True