(method, fill_value)
| 107 | ) |
| 108 | @requires_scipy |
| 109 | def test_interpolate_pd_compat(method, fill_value) -> None: |
| 110 | shapes = [(8, 8), (1, 20), (20, 1), (100, 100)] |
| 111 | frac_nans = [0, 0.5, 1] |
| 112 | |
| 113 | for shape, frac_nan in itertools.product(shapes, frac_nans): |
| 114 | da, df = make_interpolate_example_data(shape, frac_nan) |
| 115 | |
| 116 | for dim in ["time", "x"]: |
| 117 | actual = da.interpolate_na(method=method, dim=dim, fill_value=fill_value) |
| 118 | # need limit_direction="both" here, to let pandas fill |
| 119 | # in both directions instead of default forward direction only |
| 120 | expected = df.interpolate( |
| 121 | method=method, |
| 122 | axis=da.get_axis_num(dim), |
| 123 | limit_direction="both", |
| 124 | fill_value=fill_value, |
| 125 | ) |
| 126 | |
| 127 | if method == "linear": |
| 128 | # Note, Pandas does not take left/right fill_value into account |
| 129 | # for the numpy linear methods. |
| 130 | # see https://github.com/pandas-dev/pandas/issues/55144 |
| 131 | # This aligns the pandas output with the xarray output |
| 132 | fixed = expected.values.copy() |
| 133 | fixed[pd.isnull(actual.values)] = np.nan |
| 134 | fixed[actual.values == fill_value] = fill_value |
| 135 | else: |
| 136 | fixed = expected.values |
| 137 | |
| 138 | np.testing.assert_allclose(actual.values, fixed) |
| 139 | |
| 140 | |
| 141 | @requires_scipy |
nothing calls this directly
no test coverage detected
searching dependent graphs…