(shape, frac_nan, seed=12345, non_uniform=False)
| 69 | |
| 70 | |
| 71 | def make_interpolate_example_data(shape, frac_nan, seed=12345, non_uniform=False): |
| 72 | rs = np.random.default_rng(seed) |
| 73 | vals = rs.normal(size=shape) |
| 74 | if frac_nan == 1: |
| 75 | vals[:] = np.nan |
| 76 | elif frac_nan == 0: |
| 77 | pass |
| 78 | else: |
| 79 | n_missing = int(vals.size * frac_nan) |
| 80 | |
| 81 | ys = np.arange(shape[0]) |
| 82 | xs = np.arange(shape[1]) |
| 83 | if n_missing: |
| 84 | np.random.shuffle(ys) |
| 85 | ys = ys[:n_missing] |
| 86 | |
| 87 | np.random.shuffle(xs) |
| 88 | xs = xs[:n_missing] |
| 89 | |
| 90 | vals[ys, xs] = np.nan |
| 91 | |
| 92 | if non_uniform: |
| 93 | # construct a datetime index that has irregular spacing |
| 94 | deltas = pd.to_timedelta(rs.normal(size=shape[0], scale=10), unit="D") |
| 95 | coords = {"time": (pd.Timestamp("2000-01-01") + deltas).sort_values()} |
| 96 | else: |
| 97 | coords = {"time": pd.date_range("2000-01-01", freq="D", periods=shape[0])} |
| 98 | da = xr.DataArray(vals, dims=("time", "x"), coords=coords) |
| 99 | df = da.to_pandas() |
| 100 | |
| 101 | return da, df |
| 102 | |
| 103 | |
| 104 | @pytest.mark.parametrize("fill_value", [None, np.nan, 47.11]) |
no test coverage detected
searching dependent graphs…