@@ -183,15 +183,12 @@ def clean_interp_method(method: str, index: Index, **kwargs) -> str:
183
183
return method
184
184
185
185
186
- def find_valid_index (
187
- values , * , how : str , is_valid : npt .NDArray [np .bool_ ]
188
- ) -> int | None :
186
+ def find_valid_index (how : str , is_valid : npt .NDArray [np .bool_ ]) -> int | None :
189
187
"""
190
- Retrieves the index of the first valid value.
188
+ Retrieves the positional index of the first valid value.
191
189
192
190
Parameters
193
191
----------
194
- values : ndarray or ExtensionArray
195
192
how : {'first', 'last'}
196
193
Use this parameter to change between the first or last valid index.
197
194
is_valid: np.ndarray
@@ -203,17 +200,17 @@ def find_valid_index(
203
200
"""
204
201
assert how in ["first" , "last" ]
205
202
206
- if len (values ) == 0 : # early stop
203
+ if len (is_valid ) == 0 : # early stop
207
204
return None
208
205
209
- if values .ndim == 2 :
206
+ if is_valid .ndim == 2 :
210
207
is_valid = is_valid .any (axis = 1 ) # reduce axis 1
211
208
212
209
if how == "first" :
213
210
idxpos = is_valid [::].argmax ()
214
211
215
212
elif how == "last" :
216
- idxpos = len (values ) - 1 - is_valid [::- 1 ].argmax ()
213
+ idxpos = len (is_valid ) - 1 - is_valid [::- 1 ].argmax ()
217
214
218
215
chk_notna = is_valid [idxpos ]
219
216
@@ -417,12 +414,12 @@ def _interpolate_1d(
417
414
# These are sets of index pointers to invalid values... i.e. {0, 1, etc...
418
415
all_nans = set (np .flatnonzero (invalid ))
419
416
420
- first_valid_index = find_valid_index (yvalues , how = "first" , is_valid = valid )
417
+ first_valid_index = find_valid_index (how = "first" , is_valid = valid )
421
418
if first_valid_index is None : # no nan found in start
422
419
first_valid_index = 0
423
420
start_nans = set (range (first_valid_index ))
424
421
425
- last_valid_index = find_valid_index (yvalues , how = "last" , is_valid = valid )
422
+ last_valid_index = find_valid_index (how = "last" , is_valid = valid )
426
423
if last_valid_index is None : # no nan found in end
427
424
last_valid_index = len (yvalues )
428
425
end_nans = set (range (1 + last_valid_index , len (valid )))
@@ -766,10 +763,10 @@ def _interpolate_with_limit_area(
766
763
is_valid = ~ invalid
767
764
768
765
if not invalid .all ():
769
- first = find_valid_index (values , how = "first" , is_valid = is_valid )
766
+ first = find_valid_index (how = "first" , is_valid = is_valid )
770
767
if first is None :
771
768
first = 0
772
- last = find_valid_index (values , how = "last" , is_valid = is_valid )
769
+ last = find_valid_index (how = "last" , is_valid = is_valid )
773
770
if last is None :
774
771
last = len (values )
775
772
0 commit comments