diff --git a/pandas/core/indexers/utils.py b/pandas/core/indexers/utils.py index b089be3469d87..cfc49b8083267 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, 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 length is not required):