(
date, unit: NPDatetimeUnitOptions, ref_date: pd.Timestamp
)
| 387 | |
| 388 | |
| 389 | def _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 | |
| 413 | def _check_timedelta_range(value, data_unit, time_unit): |
no test coverage detected
searching dependent graphs…