From e2e6f396d70fe1432f26b55ff32ddd5afb580dfd Mon Sep 17 00:00:00 2001 From: tp Date: Sat, 16 Jun 2018 18:46:33 +0100 Subject: [PATCH 1/2] Improve example for Index.get_indexer --- pandas/core/indexes/base.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 6a56278b0da49..a9ef58e54b2a5 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -3148,8 +3148,12 @@ def droplevel(self, level=0): Examples -------- - >>> indexer = index.get_indexer(new_index) - >>> new_values = cur_values.take(indexer) + >>> index = Index(['c', 'a', 'b']) + >>> index.get_indexer(['a', 'b', 'x']) + array([ 1, 2, -1], dtype=int32) + + Notice that the return value is an array of locations in ``index`` + and ``x`` is marked by -1, as it is not in ``index``. Returns ------- From 64b87e79414684d230d90d21685b7396fb21af01 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Tue, 19 Jun 2018 10:19:47 +0200 Subject: [PATCH 2/2] small edits --- pandas/core/indexes/base.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index a9ef58e54b2a5..ffe8ea51a64a2 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -3146,21 +3146,22 @@ def droplevel(self, level=0): .. versionadded:: 0.21.0 (list-like tolerance) + Returns + ------- + indexer : ndarray of int + Integers from 0 to n - 1 indicating that the index at these + positions matches the corresponding target values. Missing values + in the target are marked by -1. + Examples -------- - >>> index = Index(['c', 'a', 'b']) + >>> index = pd.Index(['c', 'a', 'b']) >>> index.get_indexer(['a', 'b', 'x']) - array([ 1, 2, -1], dtype=int32) + array([ 1, 2, -1]) Notice that the return value is an array of locations in ``index`` and ``x`` is marked by -1, as it is not in ``index``. - Returns - ------- - indexer : ndarray of int - Integers from 0 to n - 1 indicating that the index at these - positions matches the corresponding target values. Missing values - in the target are marked by -1. """ @Appender(_index_shared_docs['get_indexer'] % _index_doc_kwargs)