From 4014a60352b21e36ec390f361815e66f96ee783c Mon Sep 17 00:00:00 2001 From: Mohammad Jafar Mashhadi Date: Sat, 1 Aug 2020 10:09:37 -0600 Subject: [PATCH 1/2] #31054 Added alignable boolean series and its example to `.loc` docs. Fixed formatting --- pandas/core/indexing.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 04d1dbceb3342..43d78a28a878d 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -255,6 +255,8 @@ def loc(self) -> "_LocIndexer": - A boolean array of the same length as the axis being sliced, e.g. ``[True, False, True]``. + - An alignable boolean series. Index of the key will be aligned before + masking. - A ``callable`` function with one argument (the calling Series or DataFrame) and that returns valid output for indexing (one of the above) @@ -264,6 +266,8 @@ def loc(self) -> "_LocIndexer": ------ KeyError If any items are not found. + IndexingError + If an indexed key is passed and its index is unalignable to the index. See Also -------- @@ -319,6 +323,13 @@ def loc(self) -> "_LocIndexer": max_speed shield sidewinder 7 8 + Alignable boolean series: + + >>> df.loc[pd.Series([False, True, False], + ... index=['viper', 'sidewinder', 'cobra'])] + max_speed shield + sidewinder 7 8 + Conditional that returns a boolean Series >>> df.loc[df['shield'] > 6] From 6774b78cbe56c466674286f1701f1b64abf72d7f Mon Sep 17 00:00:00 2001 From: Mohammad Jafar Mashhadi Date: Sat, 1 Aug 2020 20:16:38 -0600 Subject: [PATCH 2/2] Applied comments to fix grammatical issues --- pandas/core/indexing.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 43d78a28a878d..dd81823055390 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -255,7 +255,7 @@ def loc(self) -> "_LocIndexer": - A boolean array of the same length as the axis being sliced, e.g. ``[True, False, True]``. - - An alignable boolean series. Index of the key will be aligned before + - An alignable boolean Series. The index of the key will be aligned before masking. - A ``callable`` function with one argument (the calling Series or DataFrame) and that returns valid output for indexing (one of the above) @@ -267,7 +267,7 @@ def loc(self) -> "_LocIndexer": KeyError If any items are not found. IndexingError - If an indexed key is passed and its index is unalignable to the index. + If an indexed key is passed and its index is unalignable to the frame index. See Also -------- @@ -323,7 +323,7 @@ def loc(self) -> "_LocIndexer": max_speed shield sidewinder 7 8 - Alignable boolean series: + Alignable boolean Series: >>> df.loc[pd.Series([False, True, False], ... index=['viper', 'sidewinder', 'cobra'])]