|
8 | 8 |
|
9 | 9 | from flox.xarray import rechunk_for_blockwise, xarray_reduce
|
10 | 10 |
|
11 |
| -from . import assert_equal, has_dask, raise_if_dask_computes, requires_dask |
| 11 | +from . import ( |
| 12 | + assert_equal, |
| 13 | + has_dask, |
| 14 | + raise_if_dask_computes, |
| 15 | + requires_cftime, |
| 16 | + requires_dask, |
| 17 | +) |
12 | 18 |
|
13 | 19 | if has_dask:
|
14 | 20 | import dask
|
@@ -178,10 +184,18 @@ def test_validate_expected_groups(expected_groups):
|
178 | 184 | )
|
179 | 185 |
|
180 | 186 |
|
| 187 | +@requires_cftime |
181 | 188 | @requires_dask
|
182 | 189 | def test_xarray_reduce_single_grouper(engine):
|
183 | 190 | # DataArray
|
184 |
| - ds = xr.tutorial.open_dataset("rasm", chunks={"time": 9}) |
| 191 | + ds = xr.Dataset( |
| 192 | + {"Tair": (("time", "x", "y"), dask.array.ones((36, 205, 275), chunks=(9, -1, -1)))}, |
| 193 | + coords={ |
| 194 | + "time": xr.date_range( |
| 195 | + "1980-09-01 00:00", "1983-09-18 00:00", freq="ME", calendar="noleap" |
| 196 | + ) |
| 197 | + }, |
| 198 | + ) |
185 | 199 | actual = xarray_reduce(ds.Tair, ds.time.dt.month, func="mean", engine=engine)
|
186 | 200 | expected = ds.Tair.groupby("time.month").mean()
|
187 | 201 | xr.testing.assert_allclose(actual, expected)
|
@@ -355,7 +369,14 @@ def test_xarray_groupby_bins(chunks, engine):
|
355 | 369 | def test_func_is_aggregation():
|
356 | 370 | from flox.aggregations import mean
|
357 | 371 |
|
358 |
| - ds = xr.tutorial.open_dataset("rasm", chunks={"time": 9}) |
| 372 | + ds = xr.Dataset( |
| 373 | + {"Tair": (("time", "x", "y"), dask.array.ones((36, 205, 275), chunks=(9, -1, -1)))}, |
| 374 | + coords={ |
| 375 | + "time": xr.date_range( |
| 376 | + "1980-09-01 00:00", "1983-09-18 00:00", freq="ME", calendar="noleap" |
| 377 | + ) |
| 378 | + }, |
| 379 | + ) |
359 | 380 | expected = xarray_reduce(ds.Tair, ds.time.dt.month, func="mean")
|
360 | 381 | actual = xarray_reduce(ds.Tair, ds.time.dt.month, func=mean)
|
361 | 382 | xr.testing.assert_allclose(actual, expected)
|
@@ -392,10 +413,18 @@ def test_func_is_aggregation():
|
392 | 413 | @requires_dask
|
393 | 414 | @pytest.mark.parametrize("method", ["cohorts", "map-reduce"])
|
394 | 415 | def test_groupby_bins_indexed_coordinate(method):
|
395 |
| - ds = ( |
396 |
| - xr.tutorial.open_dataset("air_temperature") |
397 |
| - .isel(time=slice(100)) |
398 |
| - .chunk({"time": 20, "lat": 5}) |
| 416 | + ds = xr.Dataset( |
| 417 | + { |
| 418 | + "air": ( |
| 419 | + ("time", "lat", "lon"), |
| 420 | + dask.array.random.random((125, 25, 53), chunks=(20, 5, -1)), |
| 421 | + ) |
| 422 | + }, |
| 423 | + coords={ |
| 424 | + "time": pd.date_range("2013-01-01", "2013-02-01", freq="6H"), |
| 425 | + "lat": np.arange(75.0, 14.9, -2.5), |
| 426 | + "lon": np.arange(200.0, 331.0, 2.5), |
| 427 | + }, |
399 | 428 | )
|
400 | 429 | bins = [40, 50, 60, 70]
|
401 | 430 | expected = ds.groupby_bins("lat", bins=bins).mean(keep_attrs=True, dim=...)
|
|
0 commit comments