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

Function test_cftime_range

xarray/tests/test_cftime_offsets.py:1240–1274  ·  view source on GitHub ↗
(
    start, end, periods, freq, inclusive, normalize, calendar, expected_date_args
)

Source from the content-addressed store, hash-verified

1238 ids=_id_func,
1239)
1240def test_cftime_range(
1241 start, end, periods, freq, inclusive, normalize, calendar, expected_date_args
1242):
1243 date_type = get_date_type(calendar)
1244 expected_dates = list(starmap(date_type, expected_date_args))
1245
1246 if isinstance(start, tuple):
1247 start = date_type(*start)
1248 if isinstance(end, tuple):
1249 end = date_type(*end)
1250
1251 with pytest.warns(FutureWarning):
1252 result = cftime_range(
1253 start=start,
1254 end=end,
1255 periods=periods,
1256 freq=freq,
1257 inclusive=inclusive,
1258 normalize=normalize,
1259 calendar=calendar,
1260 )
1261 resulting_dates = result.values
1262
1263 assert isinstance(result, CFTimeIndex)
1264
1265 if freq is not None:
1266 np.testing.assert_equal(resulting_dates, expected_dates)
1267 else:
1268 # If we create a linear range of dates using cftime.num2date
1269 # we will not get exact round number dates. This is because
1270 # datetime arithmetic in cftime is accurate approximately to
1271 # 1 millisecond (see https://unidata.github.io/cftime/api.html).
1272 deltas = resulting_dates - expected_dates
1273 deltas = np.array([delta.total_seconds() for delta in deltas])
1274 assert np.max(np.abs(deltas)) < 0.001
1275
1276
1277def test_date_range_name():

Callers

nothing calls this directly

Calls 5

get_date_typeFunction · 0.90
cftime_rangeFunction · 0.90
date_typeFunction · 0.85
total_secondsMethod · 0.80
maxMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…