@@ -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 ])
@@ -66,28 +70,24 @@ def check_setitem_lengths(indexer, value, values) -> None:
66
70
"""
67
71
Validate that value and indexer are the same length.
68
72
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.
72
77
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
81
-
82
- Returns
83
- -------
84
- None
85
+ Values being set into.
85
86
86
87
Raises
87
88
------
88
89
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.
91
91
"""
92
92
# boolean with truth values == len of the value is ok too
93
93
if isinstance (indexer , (np .ndarray , list )):
@@ -122,7 +122,7 @@ def validate_indices(indices: np.ndarray, n: int) -> None:
122
122
----------
123
123
indices : ndarray
124
124
n : int
125
- length of the array being indexed
125
+ Length of the array being indexed.
126
126
127
127
Raises
128
128
------
@@ -144,11 +144,11 @@ def validate_indices(indices: np.ndarray, n: int) -> None:
144
144
if len (indices ):
145
145
min_idx = indices .min ()
146
146
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 )
150
149
151
150
max_idx = indices .max ()
151
+
152
152
if max_idx >= n :
153
153
raise IndexError ("indices are out-of-bounds" )
154
154
@@ -167,27 +167,27 @@ def maybe_convert_indices(indices, n: int):
167
167
Parameters
168
168
----------
169
169
indices : array-like
170
- The array of indices that we are to convert.
170
+ Array of indices that we are to convert.
171
171
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.
173
173
174
174
Returns
175
175
-------
176
- valid_indices : array-like
176
+ array-like
177
177
An array-like of positive indices that correspond to the ones
178
178
that were passed in initially to this function.
179
179
180
180
Raises
181
181
------
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.
184
185
"""
185
-
186
186
if isinstance (indices , list ):
187
187
indices = np .array (indices )
188
188
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.
191
191
return np .empty (0 , dtype = np .intp )
192
192
193
193
mask = indices < 0
@@ -207,7 +207,13 @@ def maybe_convert_indices(indices, n: int):
207
207
208
208
def length_of_indexer (indexer , target = None ) -> int :
209
209
"""
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.
211
217
"""
212
218
if target is not None and isinstance (indexer , slice ):
213
219
target_len = len (target )
0 commit comments