(calendar)
| 922 | |
| 923 | @requires_cftime |
| 924 | def 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) |
nothing calls this directly
no test coverage detected
searching dependent graphs…