helper function to apply interpolation along 1 dimension
(interpolator, y, x, **kwargs)
| 407 | |
| 408 | |
| 409 | def func_interpolate_na(interpolator, y, x, **kwargs): |
| 410 | """helper function to apply interpolation along 1 dimension""" |
| 411 | # reversed arguments are so that attrs are preserved from da, not index |
| 412 | # it would be nice if this wasn't necessary, works around: |
| 413 | # "ValueError: assignment destination is read-only" in assignment below |
| 414 | out = y.copy() |
| 415 | |
| 416 | nans = pd.isnull(y) |
| 417 | nonans = ~nans |
| 418 | |
| 419 | # fast track for no-nans, all nan but one, and all-nans cases |
| 420 | n_nans = nans.sum() |
| 421 | if n_nans == 0 or n_nans >= len(y) - 1: |
| 422 | return y |
| 423 | |
| 424 | f = interpolator(x[nonans], y[nonans], **kwargs) |
| 425 | out[nans] = f(x[nans]) |
| 426 | return out |
| 427 | |
| 428 | |
| 429 | def _bfill(arr, n=None, axis=-1): |