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

Function test__encode_datetime_with_cftime

xarray/tests/test_coding_times.py:1140–1158  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1138
1139@requires_cftime
1140def test__encode_datetime_with_cftime() -> None:
1141 # See GH 4870. cftime versions > 1.4.0 required us to adapt the
1142 # way _encode_datetime_with_cftime was written.
1143 import cftime
1144
1145 calendar = "gregorian"
1146 times = cftime.num2date([0, 1], "hours since 2000-01-01", calendar)
1147
1148 encoding_units = "days since 2000-01-01"
1149 # Since netCDF files do not support storing float128 values, we ensure that
1150 # float64 values are used by setting longdouble=False in num2date. This try
1151 # except logic can be removed when xarray's minimum version of cftime is at
1152 # least 1.6.2.
1153 try:
1154 expected = cftime.date2num(times, encoding_units, calendar, longdouble=False)
1155 except TypeError:
1156 expected = cftime.date2num(times, encoding_units, calendar)
1157 result = _encode_datetime_with_cftime(times, encoding_units, calendar)
1158 np.testing.assert_equal(result, expected)
1159
1160
1161@requires_cftime

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…