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

Function test_polyval_cftime

xarray/tests/test_computation.py:2441–2469  ·  view source on GitHub ↗
(use_dask: bool, date: str)

Source from the content-addressed store, hash-verified

2439)
2440@pytest.mark.parametrize("date", ["1970-01-01", "0753-04-21"])
2441def test_polyval_cftime(use_dask: bool, date: str) -> None:
2442 import cftime
2443
2444 x = xr.DataArray(
2445 xr.date_range(date, freq="1s", periods=3, use_cftime=True),
2446 dims="x",
2447 )
2448 coeffs = xr.DataArray([0, 1], dims="degree", coords={"degree": [0, 1]})
2449
2450 if use_dask:
2451 if not has_dask:
2452 pytest.skip("requires dask")
2453 coeffs = coeffs.chunk({"degree": 2})
2454 x = x.chunk({"x": 2})
2455
2456 with raise_if_dask_computes(max_computes=1):
2457 actual = xr.polyval(coord=x, coeffs=coeffs)
2458
2459 t0 = xr.date_range(date, periods=1)[0]
2460 offset = (t0 - cftime.DatetimeGregorian(1970, 1, 1)).total_seconds() * 1e9
2461 expected = (
2462 xr.DataArray(
2463 [0, 1e9, 2e9],
2464 dims="x",
2465 coords={"x": xr.date_range(date, freq="1s", periods=3, use_cftime=True)},
2466 )
2467 + offset
2468 )
2469 xr.testing.assert_allclose(actual, expected)
2470
2471
2472def test_polyval_degree_dim_checks() -> None:

Callers

nothing calls this directly

Calls 3

chunkMethod · 0.95
raise_if_dask_computesFunction · 0.90
total_secondsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…