MCPcopy Create free account
hub / github.com/numpy/numpy / cast_timedelta_to_timedelta

Function cast_timedelta_to_timedelta

numpy/core/src/multiarray/datetime.c:3046–3077  ·  view source on GitHub ↗

* Casts a single timedelta from having src_meta metadata into * dst_meta metadata. * * Returns 0 on success, -1 on failure. */

Source from the content-addressed store, hash-verified

3044 * Returns 0 on success, -1 on failure.
3045 */
3046NPY_NO_EXPORT int
3047cast_timedelta_to_timedelta(PyArray_DatetimeMetaData *src_meta,
3048 PyArray_DatetimeMetaData *dst_meta,
3049 npy_timedelta src_dt,
3050 npy_timedelta *dst_dt)
3051{
3052 npy_int64 num = 0, denom = 0;
3053
3054 /* If the metadata is the same, short-circuit the conversion */
3055 if (src_meta->base == dst_meta->base &&
3056 src_meta->num == dst_meta->num) {
3057 *dst_dt = src_dt;
3058 return 0;
3059 }
3060
3061 /* Get the conversion factor */
3062 get_datetime_conversion_factor(src_meta, dst_meta, &num, &denom);
3063
3064 if (num == 0) {
3065 return -1;
3066 }
3067
3068 /* Apply the scaling */
3069 if (src_dt < 0) {
3070 *dst_dt = (src_dt * num - (denom - 1)) / denom;
3071 }
3072 else {
3073 *dst_dt = src_dt * num / denom;
3074 }
3075
3076 return 0;
3077}
3078
3079/*
3080 * Returns true if the object is something that is best considered

Callers 2

Calls 1

Tested by

no test coverage detected