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

Method test_roundtrip_timedelta_data

xarray/tests/test_backends.py:786–799  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

784 assert actual.t.encoding["calendar"] == expected_calendar
785
786 def test_roundtrip_timedelta_data(self) -> None:
787 # todo: suggestion from review:
788 # roundtrip large microsecond or coarser resolution timedeltas,
789 # though we cannot test that until we fix the timedelta decoding
790 # to support large ranges
791 time_deltas = pd.to_timedelta(["1h", "2h", "NaT"]).as_unit("s") # type: ignore[arg-type, unused-ignore]
792 encoding = {"units": "seconds"}
793 expected = Dataset({"td": ("td", time_deltas), "td0": time_deltas[0]})
794 expected["td"].encoding = encoding
795 expected["td0"].encoding = encoding
796 with self.roundtrip(
797 expected, open_kwargs={"decode_timedelta": CFTimedeltaCoder(time_unit="s")}
798 ) as actual:
799 assert_identical(expected, actual)
800
801 def test_roundtrip_timedelta_data_via_dtype(
802 self, time_unit: PDDatetimeUnitOptions

Callers

nothing calls this directly

Calls 4

roundtripMethod · 0.95
DatasetClass · 0.90
assert_identicalFunction · 0.90
CFTimedeltaCoderClass · 0.85

Tested by

no test coverage detected