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

Function test_timedelta_decoding_options

xarray/tests/test_coding_times.py:2106–2132  ·  view source on GitHub ↗
(
    decode_via_units, decode_via_dtype, attrs, expect_timedelta64
)

Source from the content-addressed store, hash-verified

2104 ids=lambda x: f"{x!r}",
2105)
2106def test_timedelta_decoding_options(
2107 decode_via_units, decode_via_dtype, attrs, expect_timedelta64
2108) -> None:
2109 array = np.array([0, 1, 2], dtype=np.dtype("int64"))
2110 encoded = Variable(["time"], array, attrs=attrs)
2111
2112 # Confirm we decode to the expected dtype.
2113 decode_timedelta = CFTimedeltaCoder(
2114 time_unit="s",
2115 decode_via_units=decode_via_units,
2116 decode_via_dtype=decode_via_dtype,
2117 )
2118 decoded = conventions.decode_cf_variable(
2119 "foo", encoded, decode_timedelta=decode_timedelta
2120 )
2121 if expect_timedelta64:
2122 assert decoded.dtype == np.dtype("timedelta64[s]")
2123 else:
2124 assert decoded.dtype == np.dtype("int64")
2125
2126 # Confirm we exactly roundtrip.
2127 reencoded = conventions.encode_cf_variable(decoded)
2128
2129 expected = encoded.copy()
2130 if "dtype" not in attrs and decode_via_units:
2131 expected.attrs["dtype"] = "timedelta64[s]"
2132 assert_identical(reencoded, expected)
2133
2134
2135def test_timedelta_encoding_explicit_non_timedelta64_dtype() -> None:

Callers

nothing calls this directly

Calls 5

VariableClass · 0.90
assert_identicalFunction · 0.90
CFTimedeltaCoderClass · 0.85
dtypeMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…