Skip to content

Commit e527140

Browse files
committed
review comments
1 parent 51f35f3 commit e527140

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

doc/source/indexing.rst

+12-11
Original file line numberDiff line numberDiff line change
@@ -644,22 +644,22 @@ For getting *multiple* indexers, using ``.get_indexer``
644644
645645
.. _indexing.deprecate_loc_reindex_listlike:
646646

647-
Using loc with missing keys in a list is Deprecated
648-
---------------------------------------------------
647+
Indexing with missing list-of-labels is Deprecated
648+
--------------------------------------------------
649649

650650
.. warning::
651651

652-
Starting in 0.21.0, using ``.loc`` with a list-like containing missing key, is deprecated, in favor of ``.reindex``.
652+
Starting in 0.21.0, using ``.loc`` or ``[]`` with a list-like containing one or more missing labels, is deprecated, in favor of ``.reindex``.
653653

654-
In prior versions, using ``.loc[list-of-keys]`` would work as long as *at least 1* of the keys was found (otherwise it
654+
In prior versions, using ``.loc[list-of-labels]`` would work as long as *at least 1* of the keys was found (otherwise it
655655
would raise a ``KeyError``). This behavior is deprecated and will show a warning message pointing to this section. The
656656
recommeded alternative is to use ``.reindex()``.
657657

658658
For example.
659659

660660
.. ipython:: python
661661
662-
s = Series([1, 2, 3])
662+
s = pd.Series([1, 2, 3])
663663
s
664664
665665
Selection with all keys found is unchanged.
@@ -706,29 +706,30 @@ The idiomatic way to achieve selecting potentially not-found elmenents is via ``
706706
707707
s.reindex([1, 2, 3])
708708
709-
Alternatively, if you want to select only *valid* keys, the following is idiomatic; furthermore this is more efficient, and is guaranteed to preserve the dtype of the selection.
709+
Alternatively, if you want to select only *valid* keys, the following is idiomatic and efficient; it is guaranteed to preserve the dtype of the selection.
710710

711711
.. ipython:: python
712712
713-
keys = [1, 2, 3]
714-
s.loc[s.index & keys]
713+
labels = [1, 2, 3]
714+
s.loc[s.index.intersection(labels)]
715715
716716
Having a duplicated index will raise for a ``.reindex()``:
717717

718718
.. ipython:: python
719719
720720
s = pd.Series(np.arange(4), index=['a', 'a', 'b', 'c'])
721+
labels = ['c', 'd']
721722
722723
.. code-block:: python
723724
724-
In [17]: s.reindex(['c', 'd'])
725+
In [17]: s.reindex(labels)
725726
ValueError: cannot reindex from a duplicate axis
726727
727-
The idiomatic expression again allows this operation to proceed
728+
The idiomatic expression allows this operation to proceed.
728729

729730
.. ipython:: python
730731
731-
s.loc[s.index & ['c', 'd']]
732+
s.loc[s.index.intersection(labels)].reindex(labels)
732733
733734
.. _indexing.basics.partial_setting:
734735

doc/source/whatsnew/v0.21.0.txt

+7-7
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,18 @@ We have updated our minimum supported versions of dependencies (:issue:`15206`,
193193

194194
.. _whatsnew_0210.api_breaking.loc:
195195

196-
Indexing with a list-like containing missing keys is Deprecated
197-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
196+
Indexing with missing list-of-labels is Deprecated
197+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
198198

199-
Previously, selecting at least 1 valid key with a list-like indexer would succeed and return ``NaN`` for non-found elements.
200-
This is exactly the function of ``.reindex()``. This will now show a ``FutureWarning`` message; in the future this will raise ``KeyError`` (:issue:`15747`).
201-
This warning will trigger on a ``DataFrame`` or a ``Series`` for using ``.loc[]`` on the Index, or ``[[]]`` on a ``Series``.
199+
Previously, selecting at least 1 valid label with a list-like indexer would always succeed, returning ``NaN`` for missing labels.
200+
This will now show a ``FutureWarning``, in the future this will raise a ``KeyError`` (:issue:`15747`).
201+
This warning will trigger on a ``DataFrame`` or a ``Series`` for using ``.loc[]`` or ``[[]]`` when passing a list-of-labels with at least 1 missing label.
202202
See the :ref:`deprecation docs <indexing.deprecate_loc_reindex_listlike>`.
203203

204204

205205
.. ipython:: python
206206

207-
s = Series([1, 2, 3])
207+
s = pd.Series([1, 2, 3])
208208
s
209209

210210
Previous Behavior
@@ -223,7 +223,7 @@ Previous Behavior
223223
Current Behavior
224224

225225
In [4]: s.loc[[1, 2, 3]]
226-
Passing list-likes to .loc with any non-matching elements will raise
226+
Passing list-likes to .loc or [] with any missing label will raise
227227
KeyError in the future, you can use .reindex() as an alternative.
228228

229229
See the documentation here:

pandas/core/indexing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,7 @@ def _has_valid_type(self, key, axis):
14371437
# code, so we want to avoid warning & then
14381438
# just raising
14391439
_missing_key_warning = textwrap.dedent("""
1440-
Passing list-likes to .loc with any non-matching labels will raise
1440+
Passing list-likes to .loc or [] with any missing label will raise
14411441
KeyError in the future, you can use .reindex() as an alternative.
14421442
14431443
See the documentation here:

0 commit comments

Comments
 (0)