Skip to content

Commit 80afcdd

Browse files
author
MomIsBestFriend
committed
DOC: Cleaned docstrings
1 parent 835f207 commit 80afcdd

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

pandas/core/indexers.py

+33-27
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ 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
31-
30+
"""
31+
Returns
32+
-------
33+
bool
34+
True if we are all scalar indexers.
35+
"""
3236
if arr_value.ndim == 1:
3337
if not isinstance(indexer, tuple):
3438
indexer = tuple([indexer])
@@ -66,28 +70,24 @@ def check_setitem_lengths(indexer, value, values) -> None:
6670
"""
6771
Validate that value and indexer are the same length.
6872
69-
An special-case is allowed for when the indexer is a boolean array
70-
and the number of true values equals the length of ``value``. In
71-
this case, no exception is raised.
73+
A special-case is allowed for when the indexer is a
74+
boolean array and the number of true values equals
75+
the length of ``value``.
76+
In this case, no exception is raised.
7277
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
81-
82-
Returns
83-
-------
84-
None
85+
Values being set into.
8586
8687
Raises
8788
------
8889
ValueError
89-
When the indexer is an ndarray or list and the lengths don't
90-
match.
90+
When the indexer is an ndarray or list and the lengths don't match.
9191
"""
9292
# boolean with truth values == len of the value is ok too
9393
if isinstance(indexer, (np.ndarray, list)):
@@ -122,7 +122,7 @@ def validate_indices(indices: np.ndarray, n: int) -> None:
122122
----------
123123
indices : ndarray
124124
n : int
125-
length of the array being indexed
125+
Length of the array being indexed.
126126
127127
Raises
128128
------
@@ -144,11 +144,11 @@ def validate_indices(indices: np.ndarray, n: int) -> None:
144144
if len(indices):
145145
min_idx = indices.min()
146146
if min_idx < -1:
147-
raise ValueError(
148-
f"'indices' contains values less than allowed ({min_idx} < -1)"
149-
)
147+
msg = f"'indices' contains values less than allowed ({min_idx} < -1)"
148+
raise ValueError(msg)
150149

151150
max_idx = indices.max()
151+
152152
if max_idx >= n:
153153
raise IndexError("indices are out-of-bounds")
154154

@@ -167,27 +167,27 @@ def maybe_convert_indices(indices, n: int):
167167
Parameters
168168
----------
169169
indices : array-like
170-
The array of indices that we are to convert.
170+
Array of indices that we are to convert.
171171
n : int
172-
The number of elements in the array that we are indexing.
172+
Number of elements in the array that we are indexing.
173173
174174
Returns
175175
-------
176-
valid_indices : array-like
176+
array-like
177177
An array-like of positive indices that correspond to the ones
178178
that were passed in initially to this function.
179179
180180
Raises
181181
------
182-
IndexError : one of the converted indices either exceeded the number
183-
of elements (specified by `n`) OR was still negative.
182+
IndexError
183+
One of the converted indices either exceeded the number of,
184+
elements (specified by `n`), or was still negative.
184185
"""
185-
186186
if isinstance(indices, list):
187187
indices = np.array(indices)
188188
if len(indices) == 0:
189-
# If list is empty, np.array will return float and cause indexing
190-
# errors.
189+
# If `indices` is empty, `np.array` will return a float,
190+
# and will cause indexing errors.
191191
return np.empty(0, dtype=np.intp)
192192

193193
mask = indices < 0
@@ -207,7 +207,13 @@ def maybe_convert_indices(indices, n: int):
207207

208208
def length_of_indexer(indexer, target=None) -> int:
209209
"""
210-
return the length of a single non-tuple indexer which could be a slice
210+
Checks the length of a given indexer.
211+
212+
Returns
213+
-------
214+
int
215+
Length of a single non-tuple indexer,
216+
which could be a slice.
211217
"""
212218
if target is not None and isinstance(indexer, slice):
213219
target_len = len(target)

0 commit comments

Comments
 (0)