@@ -27,8 +27,13 @@ def is_list_like_indexer(key) -> bool:
27
27
28
28
29
29
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.
31
32
33
+ Returns
34
+ -------
35
+ bool
36
+ """
32
37
if arr_value .ndim == 1 :
33
38
if not isinstance (indexer , tuple ):
34
39
indexer = tuple ([indexer ])
@@ -73,11 +78,11 @@ def check_setitem_lengths(indexer, value, values) -> None:
73
78
Parameters
74
79
----------
75
80
indexer : sequence
76
- The key for the setitem
81
+ Key for the setitem.
77
82
value : array-like
78
- The value for the setitem
83
+ Value for the setitem.
79
84
values : array-like
80
- The values being set into
85
+ Values being set into.
81
86
82
87
Returns
83
88
-------
@@ -86,8 +91,7 @@ def check_setitem_lengths(indexer, value, values) -> None:
86
91
Raises
87
92
------
88
93
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.
91
95
"""
92
96
# boolean with truth values == len of the value is ok too
93
97
if isinstance (indexer , (np .ndarray , list )):
@@ -122,7 +126,7 @@ def validate_indices(indices: np.ndarray, n: int) -> None:
122
126
----------
123
127
indices : ndarray
124
128
n : int
125
- length of the array being indexed
129
+ Length of the array being indexed.
126
130
127
131
Raises
128
132
------
@@ -144,9 +148,8 @@ def validate_indices(indices: np.ndarray, n: int) -> None:
144
148
if len (indices ):
145
149
min_idx = indices .min ()
146
150
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 )
150
153
151
154
max_idx = indices .max ()
152
155
if max_idx >= n :
@@ -167,27 +170,27 @@ def maybe_convert_indices(indices, n: int):
167
170
Parameters
168
171
----------
169
172
indices : array-like
170
- The array of indices that we are to convert.
173
+ Array of indices that we are to convert.
171
174
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.
173
176
174
177
Returns
175
178
-------
176
- valid_indices : array-like
179
+ array-like
177
180
An array-like of positive indices that correspond to the ones
178
181
that were passed in initially to this function.
179
182
180
183
Raises
181
184
------
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.
184
188
"""
185
-
186
189
if isinstance (indices , list ):
187
190
indices = np .array (indices )
188
191
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.
191
194
return np .empty (0 , dtype = np .intp )
192
195
193
196
mask = indices < 0
@@ -207,7 +210,11 @@ def maybe_convert_indices(indices, n: int):
207
210
208
211
def length_of_indexer (indexer , target = None ) -> int :
209
212
"""
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
211
218
"""
212
219
if target is not None and isinstance (indexer , slice ):
213
220
target_len = len (target )
0 commit comments