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

Function test_decode_cf_time_bounds

xarray/tests/test_coding_times.py:724–762  ·  view source on GitHub ↗
(time_unit: PDDatetimeUnitOptions)

Source from the content-addressed store, hash-verified

722
723
724def test_decode_cf_time_bounds(time_unit: PDDatetimeUnitOptions) -> None:
725 da = DataArray(
726 np.arange(6, dtype="int64").reshape((3, 2)),
727 coords={"time": [1, 2, 3]},
728 dims=("time", "nbnd"),
729 name="time_bnds",
730 )
731
732 attrs = {
733 "units": "days since 2001-01",
734 "calendar": "standard",
735 "bounds": "time_bnds",
736 }
737
738 ds = da.to_dataset()
739 ds["time"].attrs.update(attrs)
740 _update_bounds_attributes(ds.variables)
741 assert ds.variables["time_bnds"].attrs == {
742 "units": "days since 2001-01",
743 "calendar": "standard",
744 }
745 dsc = decode_cf(ds, decode_times=CFDatetimeCoder(time_unit=time_unit))
746 assert dsc.time_bnds.dtype == np.dtype(f"=M8[{time_unit}]")
747 dsc = decode_cf(ds, decode_times=False)
748 assert dsc.time_bnds.dtype == np.dtype("int64")
749
750 # Do not overwrite existing attrs
751 ds = da.to_dataset()
752 ds["time"].attrs.update(attrs)
753 bnd_attr = {"units": "hours since 2001-01", "calendar": "noleap"}
754 ds["time_bnds"].attrs.update(bnd_attr)
755 _update_bounds_attributes(ds.variables)
756 assert ds.variables["time_bnds"].attrs == bnd_attr
757
758 # If bounds variable not available do not complain
759 ds = da.to_dataset()
760 ds["time"].attrs.update(attrs)
761 ds["time"].attrs["bounds"] = "fake_var"
762 _update_bounds_attributes(ds.variables)
763
764
765@requires_cftime

Callers

nothing calls this directly

Calls 8

to_datasetMethod · 0.95
DataArrayClass · 0.90
decode_cfFunction · 0.90
CFDatetimeCoderClass · 0.85
arangeMethod · 0.80
updateMethod · 0.45
dtypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…