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

Function test_time_units_with_timezone_roundtrip

xarray/tests/test_coding_times.py:924–948  ·  view source on GitHub ↗
(calendar)

Source from the content-addressed store, hash-verified

922
923@requires_cftime
924def test_time_units_with_timezone_roundtrip(calendar) -> None:
925 # Regression test for GH 2649
926 expected_units = "days since 2000-01-01T00:00:00-05:00"
927 expected_num_dates = np.array([1, 2, 3])
928 dates = decode_cf_datetime(expected_num_dates, expected_units, calendar)
929
930 # Check that dates were decoded to UTC; here the hours should all
931 # equal 5.
932 result_hours = DataArray(dates).dt.hour
933 expected_hours = DataArray([5, 5, 5])
934 assert_equal(result_hours, expected_hours)
935
936 # Check that the encoded values are accurately roundtripped.
937 result_num_dates, result_units, result_calendar = encode_cf_datetime(
938 dates, expected_units, calendar
939 )
940
941 if calendar in _STANDARD_CALENDARS:
942 assert_duckarray_equal(result_num_dates, expected_num_dates)
943 else:
944 # cftime datetime arithmetic is not quite exact.
945 assert_duckarray_allclose(result_num_dates, expected_num_dates)
946
947 assert result_units == expected_units
948 assert result_calendar == calendar
949
950
951@pytest.mark.parametrize("calendar", _STANDARD_CALENDARS)

Callers

nothing calls this directly

Calls 6

decode_cf_datetimeFunction · 0.90
DataArrayClass · 0.90
assert_equalFunction · 0.90
encode_cf_datetimeFunction · 0.90
assert_duckarray_equalFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…