Skip to content

Commit 64617cb

Browse files
DOC: Cleaned docstrings in core/indexers.py (#30131)
Co-authored-by: Joris Van den Bossche <[email protected]>
1 parent 3577b5a commit 64617cb

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

pandas/core/indexers.py

+26-19
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@ def is_list_like_indexer(key) -> bool:
2727

2828

2929
def is_scalar_indexer(indexer, arr_value) -> bool:
30-
# return True if we are all scalar indexers
30+
"""
31+
Return True if we are all scalar indexers.
3132
33+
Returns
34+
-------
35+
bool
36+
"""
3237
if arr_value.ndim == 1:
3338
if not isinstance(indexer, tuple):
3439
indexer = tuple([indexer])
@@ -73,11 +78,11 @@ def check_setitem_lengths(indexer, value, values) -> None:
7378
Parameters
7479
----------
7580
indexer : sequence
76-
The key for the setitem
81+
Key for the setitem.
7782
value : array-like
78-
The value for the setitem
83+
Value for the setitem.
7984
values : array-like
80-
The values being set into
85+
Values being set into.
8186
8287
Returns
8388
-------
@@ -86,8 +91,7 @@ def check_setitem_lengths(indexer, value, values) -> None:
8691
Raises
8792
------
8893
ValueError
89-
When the indexer is an ndarray or list and the lengths don't
90-
match.
94+
When the indexer is an ndarray or list and the lengths don't match.
9195
"""
9296
# boolean with truth values == len of the value is ok too
9397
if isinstance(indexer, (np.ndarray, list)):
@@ -122,7 +126,7 @@ def validate_indices(indices: np.ndarray, n: int) -> None:
122126
----------
123127
indices : ndarray
124128
n : int
125-
length of the array being indexed
129+
Length of the array being indexed.
126130
127131
Raises
128132
------
@@ -144,9 +148,8 @@ def validate_indices(indices: np.ndarray, n: int) -> None:
144148
if len(indices):
145149
min_idx = indices.min()
146150
if min_idx < -1:
147-
raise ValueError(
148-
f"'indices' contains values less than allowed ({min_idx} < -1)"
149-
)
151+
msg = f"'indices' contains values less than allowed ({min_idx} < -1)"
152+
raise ValueError(msg)
150153

151154
max_idx = indices.max()
152155
if max_idx >= n:
@@ -167,27 +170,27 @@ def maybe_convert_indices(indices, n: int):
167170
Parameters
168171
----------
169172
indices : array-like
170-
The array of indices that we are to convert.
173+
Array of indices that we are to convert.
171174
n : int
172-
The number of elements in the array that we are indexing.
175+
Number of elements in the array that we are indexing.
173176
174177
Returns
175178
-------
176-
valid_indices : array-like
179+
array-like
177180
An array-like of positive indices that correspond to the ones
178181
that were passed in initially to this function.
179182
180183
Raises
181184
------
182-
IndexError : one of the converted indices either exceeded the number
183-
of elements (specified by `n`) OR was still negative.
185+
IndexError
186+
One of the converted indices either exceeded the number of,
187+
elements (specified by `n`), or was still negative.
184188
"""
185-
186189
if isinstance(indices, list):
187190
indices = np.array(indices)
188191
if len(indices) == 0:
189-
# If list is empty, np.array will return float and cause indexing
190-
# errors.
192+
# If `indices` is empty, np.array will return a float,
193+
# and will cause indexing errors.
191194
return np.empty(0, dtype=np.intp)
192195

193196
mask = indices < 0
@@ -207,7 +210,11 @@ def maybe_convert_indices(indices, n: int):
207210

208211
def length_of_indexer(indexer, target=None) -> int:
209212
"""
210-
return the length of a single non-tuple indexer which could be a slice
213+
Return the length of a single non-tuple indexer which could be a slice.
214+
215+
Returns
216+
-------
217+
int
211218
"""
212219
if target is not None and isinstance(indexer, slice):
213220
target_len = len(target)

0 commit comments

Comments
 (0)