@@ -170,7 +170,9 @@ def clean_interp_method(method: str, index: Index, **kwargs) -> str:
170
170
return method
171
171
172
172
173
- def find_valid_index (values , * , how : str ) -> int | None :
173
+ def find_valid_index (
174
+ values , * , how : str , is_valid : npt .NDArray [np .bool_ ]
175
+ ) -> int | None :
174
176
"""
175
177
Retrieves the index of the first valid value.
176
178
@@ -179,6 +181,8 @@ def find_valid_index(values, *, how: str) -> int | None:
179
181
values : ndarray or ExtensionArray
180
182
how : {'first', 'last'}
181
183
Use this parameter to change between the first or last valid index.
184
+ is_valid: np.ndarray
185
+ Mask to find na_values.
182
186
183
187
Returns
184
188
-------
@@ -189,8 +193,6 @@ def find_valid_index(values, *, how: str) -> int | None:
189
193
if len (values ) == 0 : # early stop
190
194
return None
191
195
192
- is_valid = ~ isna (values )
193
-
194
196
if values .ndim == 2 :
195
197
is_valid = is_valid .any (axis = 1 ) # reduce axis 1
196
198
@@ -204,7 +206,9 @@ def find_valid_index(values, *, how: str) -> int | None:
204
206
205
207
if not chk_notna :
206
208
return None
207
- return idxpos
209
+ # Incompatible return value type (got "signedinteger[Any]",
210
+ # expected "Optional[int]")
211
+ return idxpos # type: ignore[return-value]
208
212
209
213
210
214
def interpolate_array_2d (
@@ -400,12 +404,12 @@ def _interpolate_1d(
400
404
# These are sets of index pointers to invalid values... i.e. {0, 1, etc...
401
405
all_nans = set (np .flatnonzero (invalid ))
402
406
403
- first_valid_index = find_valid_index (yvalues , how = "first" )
407
+ first_valid_index = find_valid_index (yvalues , how = "first" , is_valid = valid )
404
408
if first_valid_index is None : # no nan found in start
405
409
first_valid_index = 0
406
410
start_nans = set (range (first_valid_index ))
407
411
408
- last_valid_index = find_valid_index (yvalues , how = "last" )
412
+ last_valid_index = find_valid_index (yvalues , how = "last" , is_valid = valid )
409
413
if last_valid_index is None : # no nan found in end
410
414
last_valid_index = len (yvalues )
411
415
end_nans = set (range (1 + last_valid_index , len (valid )))
@@ -738,12 +742,13 @@ def _interpolate_with_limit_area(
738
742
"""
739
743
740
744
invalid = isna (values )
745
+ is_valid = ~ invalid
741
746
742
747
if not invalid .all ():
743
- first = find_valid_index (values , how = "first" )
748
+ first = find_valid_index (values , how = "first" , is_valid = is_valid )
744
749
if first is None :
745
750
first = 0
746
- last = find_valid_index (values , how = "last" )
751
+ last = find_valid_index (values , how = "last" , is_valid = is_valid )
747
752
if last is None :
748
753
last = len (values )
749
754
0 commit comments