@@ -27,8 +27,12 @@ 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
31
-
30
+ """
31
+ Returns
32
+ -------
33
+ bool
34
+ True if we are all scalar indexers.
35
+ """
32
36
if arr_value .ndim == 1 :
33
37
if not isinstance (indexer , tuple ):
34
38
indexer = tuple ([indexer ])
@@ -73,21 +77,16 @@ def check_setitem_lengths(indexer, value, values) -> None:
73
77
Parameters
74
78
----------
75
79
indexer : sequence
76
- The key for the setitem
80
+ Key for the setitem.
77
81
value : array-like
78
- The value for the setitem
82
+ Value for the setitem.
79
83
values : array-like
80
- The values being set into
81
-
82
- Returns
83
- -------
84
- None
84
+ Values being set into.
85
85
86
86
Raises
87
87
------
88
88
ValueError
89
- When the indexer is an ndarray or list and the lengths don't
90
- match.
89
+ When the indexer is an ndarray or list and the lengths don't match.
91
90
"""
92
91
# boolean with truth values == len of the value is ok too
93
92
if isinstance (indexer , (np .ndarray , list )):
@@ -122,7 +121,7 @@ def validate_indices(indices: np.ndarray, n: int) -> None:
122
121
----------
123
122
indices : ndarray
124
123
n : int
125
- length of the array being indexed
124
+ Length of the array being indexed.
126
125
127
126
Raises
128
127
------
@@ -144,11 +143,11 @@ def validate_indices(indices: np.ndarray, n: int) -> None:
144
143
if len (indices ):
145
144
min_idx = indices .min ()
146
145
if min_idx < - 1 :
147
- raise ValueError (
148
- f"'indices' contains values less than allowed ({ min_idx } < -1)"
149
- )
146
+ msg = f"'indices' contains values less than allowed ({ min_idx } < -1)"
147
+ raise ValueError (msg )
150
148
151
149
max_idx = indices .max ()
150
+
152
151
if max_idx >= n :
153
152
raise IndexError ("indices are out-of-bounds" )
154
153
@@ -167,27 +166,27 @@ def maybe_convert_indices(indices, n: int):
167
166
Parameters
168
167
----------
169
168
indices : array-like
170
- The array of indices that we are to convert.
169
+ Array of indices that we are to convert.
171
170
n : int
172
- The number of elements in the array that we are indexing.
171
+ Number of elements in the array that we are indexing.
173
172
174
173
Returns
175
174
-------
176
- valid_indices : array-like
175
+ array-like
177
176
An array-like of positive indices that correspond to the ones
178
177
that were passed in initially to this function.
179
178
180
179
Raises
181
180
------
182
- IndexError : one of the converted indices either exceeded the number
183
- of elements (specified by `n`) OR was still negative.
181
+ IndexError
182
+ One of the converted indices either exceeded the number of,
183
+ elements (specified by `n`), or was still negative.
184
184
"""
185
-
186
185
if isinstance (indices , list ):
187
186
indices = np .array (indices )
188
187
if len (indices ) == 0 :
189
- # If list is empty, np.array will return float and cause indexing
190
- # errors.
188
+ # If `indices` is empty, ` np.array` will return a float,
189
+ # and will cause indexing errors.
191
190
return np .empty (0 , dtype = np .intp )
192
191
193
192
mask = indices < 0
@@ -207,7 +206,13 @@ def maybe_convert_indices(indices, n: int):
207
206
208
207
def length_of_indexer (indexer , target = None ) -> int :
209
208
"""
210
- return the length of a single non-tuple indexer which could be a slice
209
+ Checks the length of a given indexer.
210
+
211
+ Returns
212
+ -------
213
+ int
214
+ Length of a single non-tuple indexer,
215
+ which could be a slice.
211
216
"""
212
217
if target is not None and isinstance (indexer , slice ):
213
218
target_len = len (target )
0 commit comments