MCPcopy Index your code
hub / github.com/pydata/xarray / test_interpolate_pd_compat

Function test_interpolate_pd_compat

xarray/tests/test_missing.py:109–138  ·  view source on GitHub ↗
(method, fill_value)

Source from the content-addressed store, hash-verified

107)
108@requires_scipy
109def 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

Callers

nothing calls this directly

Calls 6

interpolateMethod · 0.80
interpolate_naMethod · 0.45
get_axis_numMethod · 0.45
copyMethod · 0.45
isnullMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…