MCPcopy
hub / github.com/pydata/xarray / test_cftime_datetime_mean

Function test_cftime_datetime_mean

xarray/tests/test_duck_array_ops.py:482–510  ·  view source on GitHub ↗
(dask)

Source from the content-addressed store, hash-verified

480@requires_cftime
481@pytest.mark.parametrize("dask", [False, True])
482def test_cftime_datetime_mean(dask):
483 if dask and not has_dask:
484 pytest.skip("requires dask")
485
486 times = date_range("2000", periods=4, use_cftime=True)
487 da = DataArray(times, dims=["time"])
488 da_2d = DataArray(times.values.reshape(2, 2))
489
490 if dask:
491 da = da.chunk({"time": 2})
492 da_2d = da_2d.chunk({"dim_0": 2})
493
494 expected = da.isel(time=0)
495 # one compute needed to check the array contains cftime datetimes
496 with raise_if_dask_computes(max_computes=1):
497 result = da.isel(time=0).mean()
498 assert_dask_array(result, dask)
499 assert_equal(result, expected)
500
501 expected = DataArray(times.date_type(2000, 1, 2, 12))
502 with raise_if_dask_computes(max_computes=1):
503 result = da.mean()
504 assert_dask_array(result, dask)
505 assert_equal(result, expected)
506
507 with raise_if_dask_computes(max_computes=1):
508 result = da_2d.mean()
509 assert_dask_array(result, dask)
510 assert_equal(result, expected)
511
512
513@pytest.mark.parametrize("dask", [False, True])

Callers

nothing calls this directly

Calls 8

chunkMethod · 0.95
iselMethod · 0.95
date_rangeFunction · 0.90
DataArrayClass · 0.90
raise_if_dask_computesFunction · 0.90
assert_equalFunction · 0.90
assert_dask_arrayFunction · 0.85
meanMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…