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

Function test_decode_cf

xarray/tests/test_coding_times.py:702–721  ·  view source on GitHub ↗
(calendar, time_unit: PDDatetimeUnitOptions)

Source from the content-addressed store, hash-verified

700
701@pytest.mark.parametrize("calendar", _ALL_CALENDARS)
702def test_decode_cf(calendar, time_unit: PDDatetimeUnitOptions) -> None:
703 days = [1.0, 2.0, 3.0]
704 # TODO: GH5690 — do we want to allow this type for `coords`?
705 da = DataArray(days, coords=[days], dims=["time"], name="test")
706 ds = da.to_dataset()
707
708 for v in ["test", "time"]:
709 ds[v].attrs["units"] = "days since 2001-01-01"
710 ds[v].attrs["calendar"] = calendar
711
712 if not has_cftime and calendar not in _STANDARD_CALENDAR_NAMES:
713 with pytest.raises(ValueError):
714 ds = decode_cf(ds)
715 else:
716 ds = decode_cf(ds, decode_times=CFDatetimeCoder(time_unit=time_unit))
717
718 if calendar not in _STANDARD_CALENDAR_NAMES:
719 assert ds.test.dtype == np.dtype("O")
720 else:
721 assert ds.test.dtype == np.dtype(f"=M8[{time_unit}]")
722
723
724def test_decode_cf_time_bounds(time_unit: PDDatetimeUnitOptions) -> None:

Callers

nothing calls this directly

Calls 5

to_datasetMethod · 0.95
DataArrayClass · 0.90
decode_cfFunction · 0.90
CFDatetimeCoderClass · 0.85
dtypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…