| 2171 | assert_identical(expected, actual) |
| 2172 | |
| 2173 | def test_upsample_tolerance(self) -> None: |
| 2174 | # Test tolerance keyword for upsample methods bfill, pad, nearest |
| 2175 | times = pd.date_range("2000-01-01", freq="1D", periods=2) |
| 2176 | times_upsampled = pd.date_range("2000-01-01", freq="6h", periods=5) |
| 2177 | array = DataArray(np.arange(2), [("time", times)]) |
| 2178 | |
| 2179 | # Forward fill |
| 2180 | actual = array.resample(time="6h").ffill(tolerance="12h") |
| 2181 | expected = DataArray([0.0, 0.0, 0.0, np.nan, 1.0], [("time", times_upsampled)]) |
| 2182 | assert_identical(expected, actual) |
| 2183 | |
| 2184 | # Backward fill |
| 2185 | actual = array.resample(time="6h").bfill(tolerance="12h") |
| 2186 | expected = DataArray([0.0, np.nan, 1.0, 1.0, 1.0], [("time", times_upsampled)]) |
| 2187 | assert_identical(expected, actual) |
| 2188 | |
| 2189 | # Nearest |
| 2190 | actual = array.resample(time="6h").nearest(tolerance="6h") |
| 2191 | expected = DataArray([0, 0, np.nan, 1, 1], [("time", times_upsampled)]) |
| 2192 | assert_identical(expected, actual) |
| 2193 | |
| 2194 | @requires_scipy |
| 2195 | def test_upsample_interpolate(self) -> None: |