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

Function _check_date_for_units_since_refdate

xarray/coding/times.py:389–410  ·  view source on GitHub ↗
(
    date, unit: NPDatetimeUnitOptions, ref_date: pd.Timestamp
)

Source from the content-addressed store, hash-verified

387
388
389def _check_date_for_units_since_refdate(
390 date, unit: NPDatetimeUnitOptions, ref_date: pd.Timestamp
391) -> pd.Timestamp:
392 # check for out-of-bounds floats and raise
393 if date > np.iinfo("int64").max or date < np.iinfo("int64").min:
394 raise OutOfBoundsTimedelta(
395 f"Value {date} can't be represented as Datetime/Timedelta."
396 )
397 delta = date * np.timedelta64(1, unit)
398 if not np.isnan(delta):
399 # this will raise on dtype overflow for integer dtypes
400 if date.dtype.kind == "u" and not np.int64(delta) == date:
401 raise OutOfBoundsTimedelta(
402 "DType overflow in Datetime/Timedelta calculation."
403 )
404 # this will raise on overflow if ref_date + delta
405 # can't be represented in the current ref_date resolution
406 return timestamp_as_unit(ref_date + delta, ref_date.unit)
407 else:
408 # if date is exactly NaT (np.iinfo("int64").min) return NaT
409 # to make follow-up checks work
410 return pd.Timestamp("NaT")
411
412
413def _check_timedelta_range(value, data_unit, time_unit):

Callers 1

Calls 1

timestamp_as_unitFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…