(self)
| 2113 | assert_identical(expected, actual) |
| 2114 | |
| 2115 | def test_upsample_nd(self) -> None: |
| 2116 | # Same as before, but now we try on multi-dimensional DataArrays. |
| 2117 | xs = np.arange(6) |
| 2118 | ys = np.arange(3) |
| 2119 | times = pd.date_range("2000-01-01", freq="6h", periods=5) |
| 2120 | data = np.tile(np.arange(5), (6, 3, 1)) |
| 2121 | array = DataArray(data, {"time": times, "x": xs, "y": ys}, ("x", "y", "time")) |
| 2122 | |
| 2123 | # Forward-fill |
| 2124 | actual = array.resample(time="3h").ffill() |
| 2125 | expected_data = np.repeat(data, 2, axis=-1) |
| 2126 | expected_times = times.to_series().resample("3h").asfreq().index |
| 2127 | expected_data = expected_data[..., : len(expected_times)] |
| 2128 | expected = DataArray( |
| 2129 | expected_data, |
| 2130 | {"time": expected_times, "x": xs, "y": ys}, |
| 2131 | ("x", "y", "time"), |
| 2132 | ) |
| 2133 | assert_identical(expected, actual) |
| 2134 | |
| 2135 | # Backward-fill |
| 2136 | actual = array.resample(time="3h").ffill() |
| 2137 | expected_data = np.repeat(np.flipud(data.T).T, 2, axis=-1) |
| 2138 | expected_data = np.flipud(expected_data.T).T |
| 2139 | expected_times = times.to_series().resample("3h").asfreq().index |
| 2140 | expected_data = expected_data[..., : len(expected_times)] |
| 2141 | expected = DataArray( |
| 2142 | expected_data, |
| 2143 | {"time": expected_times, "x": xs, "y": ys}, |
| 2144 | ("x", "y", "time"), |
| 2145 | ) |
| 2146 | assert_identical(expected, actual) |
| 2147 | |
| 2148 | # As frequency |
| 2149 | actual = array.resample(time="3h").asfreq() |
| 2150 | expected_data = np.repeat(data, 2, axis=-1).astype(float)[..., :-1] |
| 2151 | expected_data[..., 1::2] = np.nan |
| 2152 | expected_times = times.to_series().resample("3h").asfreq().index |
| 2153 | expected = DataArray( |
| 2154 | expected_data, |
| 2155 | {"time": expected_times, "x": xs, "y": ys}, |
| 2156 | ("x", "y", "time"), |
| 2157 | ) |
| 2158 | assert_identical(expected, actual) |
| 2159 | |
| 2160 | # Pad |
| 2161 | actual = array.resample(time="3h").pad() |
| 2162 | expected_data = np.repeat(data, 2, axis=-1) |
| 2163 | expected_data[..., 1::2] = expected_data[..., ::2] |
| 2164 | expected_data = expected_data[..., :-1] |
| 2165 | expected_times = times.to_series().resample("3h").asfreq().index |
| 2166 | expected = DataArray( |
| 2167 | expected_data, |
| 2168 | {"time": expected_times, "x": xs, "y": ys}, |
| 2169 | ("x", "y", "time"), |
| 2170 | ) |
| 2171 | assert_identical(expected, actual) |
| 2172 |
nothing calls this directly
no test coverage detected