From 2be3d5bea64cd5d13f180af28b06f0f6417dbf30 Mon Sep 17 00:00:00 2001 From: sah0725 Date: Sat, 4 Oct 2025 13:12:04 +0530 Subject: [PATCH 1/3] DOC: clarify that check_array_indexer accepts int and slice - Updated parameter documentation to explicitly mention int, slice, and other non-array indexers are accepted - Added examples showing int and slice usage - Fixes #62562 --- pandas/core/indexers/utils.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pandas/core/indexers/utils.py b/pandas/core/indexers/utils.py index b089be3469d87..07195cd6b07a2 100644 --- a/pandas/core/indexers/utils.py +++ b/pandas/core/indexers/utils.py @@ -434,10 +434,11 @@ def check_array_indexer(array: AnyArrayLike, indexer: Any) -> Any: ---------- array : array-like The array that is being indexed (only used for the length). - indexer : array-like or list-like - The array-like that's used to index. List-like input that is not yet - a numpy array or an ExtensionArray is converted to one. Other input - types are passed through as is. + indexer : array-like, list-like, int, slice, or other indexer + The indexer used for indexing. Array-like and list-like inputs that + are not yet a numpy array or an ExtensionArray are converted to one. + Non-array indexers (int, slice, Ellipsis, tuples, etc.) are passed + through as is. Returns ------- @@ -486,6 +487,13 @@ def check_array_indexer(array: AnyArrayLike, indexer: Any) -> Any: >>> pd.api.indexers.check_array_indexer(arr, mask) array([ True, False]) + Integer and slice indexers are passed through as is: + + >>> pd.api.indexers.check_array_indexer(arr, 1) + 1 + >>> pd.api.indexers.check_array_indexer(arr, slice(0, 1, 1)) + slice(0, 1, None) + Similarly for integer indexers, an integer ndarray is returned when it is a valid indexer, otherwise an error is (for integer indexers, a matching length is not required): From e62ee17db77e07bbe29a0f513be68cb486234029 Mon Sep 17 00:00:00 2001 From: sah0725 Date: Sat, 4 Oct 2025 13:51:54 +0530 Subject: [PATCH 2/3] FIX: Fix trailing whitespace --- pandas/core/indexers/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexers/utils.py b/pandas/core/indexers/utils.py index 07195cd6b07a2..bcb2d89a9b4c7 100644 --- a/pandas/core/indexers/utils.py +++ b/pandas/core/indexers/utils.py @@ -435,9 +435,9 @@ def check_array_indexer(array: AnyArrayLike, indexer: Any) -> Any: array : array-like The array that is being indexed (only used for the length). indexer : array-like, list-like, int, slice, or other indexer - The indexer used for indexing. Array-like and list-like inputs that - are not yet a numpy array or an ExtensionArray are converted to one. - Non-array indexers (int, slice, Ellipsis, tuples, etc.) are passed + The indexer used for indexing. Array-like and list-like inputs that + are not yet a numpy array or an ExtensionArray are converted to one. + Non-array indexers (int, slice, Ellipsis, tuples, etc.) are passed through as is. Returns From a906325f2a86a3d41ced8545b7ec8770ece75d2e Mon Sep 17 00:00:00 2001 From: sah0725 Date: Sat, 4 Oct 2025 14:32:57 +0530 Subject: [PATCH 3/3] FIX: Fix doctest --- pandas/core/indexers/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexers/utils.py b/pandas/core/indexers/utils.py index bcb2d89a9b4c7..cfc49b8083267 100644 --- a/pandas/core/indexers/utils.py +++ b/pandas/core/indexers/utils.py @@ -492,7 +492,7 @@ def check_array_indexer(array: AnyArrayLike, indexer: Any) -> Any: >>> pd.api.indexers.check_array_indexer(arr, 1) 1 >>> pd.api.indexers.check_array_indexer(arr, slice(0, 1, 1)) - slice(0, 1, None) + slice(0, 1, 1) Similarly for integer indexers, an integer ndarray is returned when it is a valid indexer, otherwise an error is (for integer indexers, a matching