MCPcopy Index your code
hub / github.com/pydata/xarray / test_cftime_round_accessor

Function test_cftime_round_accessor

xarray/tests/test_accessor_dt.py:680–707  ·  view source on GitHub ↗
(
    cftime_rounding_dataarray, cftime_date_type, use_dask
)

Source from the content-addressed store, hash-verified

678@requires_dask
679@pytest.mark.parametrize("use_dask", [False, True])
680def test_cftime_round_accessor(
681 cftime_rounding_dataarray, cftime_date_type, use_dask
682) -> None:
683 import dask.array as da
684
685 freq = "D"
686 expected = xr.DataArray(
687 [
688 [cftime_date_type(1, 1, 1, 0), cftime_date_type(1, 1, 2, 0)],
689 [cftime_date_type(1, 1, 2, 0), cftime_date_type(1, 1, 2, 0)],
690 ],
691 name="round",
692 )
693
694 if use_dask:
695 chunks = {"dim_0": 1}
696 # Currently a compute is done to inspect a single value of the array
697 # if it is of object dtype to check if it is a cftime.datetime (if not
698 # we raise an error when using the dt accessor).
699 with raise_if_dask_computes(max_computes=1):
700 result = cftime_rounding_dataarray.chunk(chunks).dt.round(freq)
701 expected = expected.chunk(chunks)
702 assert isinstance(result.data, da.Array)
703 assert result.chunks == expected.chunks
704 else:
705 result = cftime_rounding_dataarray.dt.round(freq)
706
707 assert_identical(result, expected)
708
709
710@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 6

chunkMethod · 0.95
raise_if_dask_computesFunction · 0.90
assert_identicalFunction · 0.90
cftime_date_typeFunction · 0.85
roundMethod · 0.45
chunkMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…