From 53b2f30223284d518cab02ae37bfd2bc8b5d761c Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Fri, 9 Dec 2022 15:33:37 +0100 Subject: [PATCH 1/5] DOC: add examples to get_indexer_non_unique --- pandas/core/indexes/base.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 5a71ac247422a..6a32b7e358916 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -5557,6 +5557,25 @@ def _should_fallback_to_positional(self) -> bool: missing : np.ndarray[np.intp] An indexer into the target of the values not found. These correspond to the -1 in the indexer array. + + Examples + -------- + >>> index = pd.Index(['c', 'b', 'a', 'b', 'b']) + >>> index.get_indexer_non_unique(['f', 'b', 's']) + (array([-1, 1, 3, 4, -1]), array([0, 2])) + + >>> index = pd.Index(['c', 'b', 'a', 'b', 'b']) + >>> index.get_indexer_non_unique(['b', 'b']) + (array([1, 3, 4, 1, 3, 4]), array([], dtype=int64)) + + >>> index = pd.Index(['c', 'b', 'a', 'b', 'b']) + >>> index.get_indexer_non_unique(['q', 'r', 't']) + (array([-1, -1, -1]), array([0, 1, 2])) + + Notice that the return value is a tuple contains two items. + The first item is an array of locations in ``index`` and ``x`` + is marked by -1, as it is not in ``index``. The second item + is a mask for new index given the current index. """ @Appender(_index_shared_docs["get_indexer_non_unique"] % _index_doc_kwargs) From 27b9ff0d43ff1c5cd7e961b9022969ee0693d89b Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Sat, 10 Dec 2022 11:38:41 +0100 Subject: [PATCH 2/5] DOC: add examples to get_indexer_non_unique II --- pandas/core/indexes/base.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 6a32b7e358916..d8caa874d8b49 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -5560,22 +5560,27 @@ def _should_fallback_to_positional(self) -> bool: Examples -------- - >>> index = pd.Index(['c', 'b', 'a', 'b', 'b']) - >>> index.get_indexer_non_unique(['f', 'b', 's']) - (array([-1, 1, 3, 4, -1]), array([0, 2])) - >>> index = pd.Index(['c', 'b', 'a', 'b', 'b']) >>> index.get_indexer_non_unique(['b', 'b']) (array([1, 3, 4, 1, 3, 4]), array([], dtype=int64)) + In the example below there are no matched values. For this reason, + the returned ``indexer`` contains only integers equal to -1. + It demonstrates no index at these positions that match the corresponding + ``target`` values. The mask [0, 1, 2] in the return value shows that the first, + second, and third elements are missing. + >>> index = pd.Index(['c', 'b', 'a', 'b', 'b']) >>> index.get_indexer_non_unique(['q', 'r', 't']) (array([-1, -1, -1]), array([0, 1, 2])) - Notice that the return value is a tuple contains two items. - The first item is an array of locations in ``index`` and ``x`` - is marked by -1, as it is not in ``index``. The second item - is a mask for new index given the current index. + >>> index = pd.Index(['c', 'b', 'a', 'b', 'b']) + >>> index.get_indexer_non_unique(['f', 'b', 's']) + (array([-1, 1, 3, 4, -1]), array([0, 2])) + + Notice that the return value is a tuple contains two items. In the example + above the first item is an array of locations in ``index``. The second + item is a mask shows that the first and third elements are missing. """ @Appender(_index_shared_docs["get_indexer_non_unique"] % _index_doc_kwargs) From ca39193b73660b93f0fa27d430342ec458e98049 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Sat, 10 Dec 2022 17:48:01 +0100 Subject: [PATCH 3/5] DOC: add examples to get_indexer_non_unique III --- pandas/core/indexes/base.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index d8caa874d8b49..70e9fdccf2315 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -5564,23 +5564,25 @@ def _should_fallback_to_positional(self) -> bool: >>> index.get_indexer_non_unique(['b', 'b']) (array([1, 3, 4, 1, 3, 4]), array([], dtype=int64)) - In the example below there are no matched values. For this reason, - the returned ``indexer`` contains only integers equal to -1. - It demonstrates no index at these positions that match the corresponding - ``target`` values. The mask [0, 1, 2] in the return value shows that the first, - second, and third elements are missing. + In the example below there are no matched values. >>> index = pd.Index(['c', 'b', 'a', 'b', 'b']) >>> index.get_indexer_non_unique(['q', 'r', 't']) (array([-1, -1, -1]), array([0, 1, 2])) + For this reason, the returned ``indexer`` contains only integers equal to -1. + It demonstrates no index at these positions that match the corresponding + ``target`` values. The mask [0, 1, 2] in the return value shows that the first, + second, and third elements are missing. + + Notice that the return value is a tuple contains two items. In the example + below the first item is an array of locations in ``index``. The second + item is a mask shows that the first and third elements are missing. + >>> index = pd.Index(['c', 'b', 'a', 'b', 'b']) >>> index.get_indexer_non_unique(['f', 'b', 's']) (array([-1, 1, 3, 4, -1]), array([0, 2])) - Notice that the return value is a tuple contains two items. In the example - above the first item is an array of locations in ``index``. The second - item is a mask shows that the first and third elements are missing. """ @Appender(_index_shared_docs["get_indexer_non_unique"] % _index_doc_kwargs) From 3d660b19cd7e8d4f97b96f851817c809b91ece70 Mon Sep 17 00:00:00 2001 From: Marco Edward Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Sat, 10 Dec 2022 16:59:07 +0000 Subject: [PATCH 4/5] Update pandas/core/indexes/base.py --- pandas/core/indexes/base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 70e9fdccf2315..9ad864caf7a39 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -5571,9 +5571,9 @@ def _should_fallback_to_positional(self) -> bool: (array([-1, -1, -1]), array([0, 1, 2])) For this reason, the returned ``indexer`` contains only integers equal to -1. - It demonstrates no index at these positions that match the corresponding - ``target`` values. The mask [0, 1, 2] in the return value shows that the first, - second, and third elements are missing. + It demonstrates that there's no match between the index and the ``target`` + values at these positions. The mask [0, 1, 2] in the return value shows that + the first, second, and third elements are missing. Notice that the return value is a tuple contains two items. In the example below the first item is an array of locations in ``index``. The second From ef7c4e81c6237d74c9053e7162ddb2d8e7a707b1 Mon Sep 17 00:00:00 2001 From: Marco Edward Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Sat, 10 Dec 2022 17:00:39 +0000 Subject: [PATCH 5/5] Update pandas/core/indexes/base.py --- pandas/core/indexes/base.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 9ad864caf7a39..8cbe6177447c1 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -5582,7 +5582,6 @@ def _should_fallback_to_positional(self) -> bool: >>> index = pd.Index(['c', 'b', 'a', 'b', 'b']) >>> index.get_indexer_non_unique(['f', 'b', 's']) (array([-1, 1, 3, 4, -1]), array([0, 2])) - """ @Appender(_index_shared_docs["get_indexer_non_unique"] % _index_doc_kwargs)