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

Function test_roundtrip_0size_timedelta

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

Source from the content-addressed store, hash-verified

2183
2184
2185def test_roundtrip_0size_timedelta(time_unit: PDDatetimeUnitOptions) -> None:
2186 # regression test for GitHub issue #10310
2187 encoding = {"units": "days", "dtype": np.dtype("int64")}
2188 data = np.array([], dtype=f"=m8[{time_unit}]")
2189 decoded = Variable(["time"], data, encoding=encoding)
2190 encoded = conventions.encode_cf_variable(decoded, name="foo")
2191 assert encoded.dtype == encoding["dtype"]
2192 assert encoded.attrs["units"] == encoding["units"]
2193 decoded = conventions.decode_cf_variable("foo", encoded, decode_timedelta=True)
2194 assert decoded.dtype == np.dtype(f"=m8[{time_unit}]")
2195 with assert_no_warnings():
2196 decoded.load()
2197 assert decoded.dtype == np.dtype("=m8[s]")
2198 assert decoded.encoding == encoding
2199
2200
2201def test_roundtrip_empty_datetime64_array(time_unit: PDDatetimeUnitOptions) -> None:

Callers

nothing calls this directly

Calls 4

loadMethod · 0.95
VariableClass · 0.90
assert_no_warningsFunction · 0.90
dtypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…