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

Function cast_datetime_to_datetime

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

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

Source from the content-addressed store, hash-verified

3010 * Returns 0 on success, -1 on failure.
3011 */
3012NPY_NO_EXPORT int
3013cast_datetime_to_datetime(PyArray_DatetimeMetaData *src_meta,
3014 PyArray_DatetimeMetaData *dst_meta,
3015 npy_datetime src_dt,
3016 npy_datetime *dst_dt)
3017{
3018 npy_datetimestruct dts;
3019
3020 /* If the metadata is the same, short-circuit the conversion */
3021 if (src_meta->base == dst_meta->base &&
3022 src_meta->num == dst_meta->num) {
3023 *dst_dt = src_dt;
3024 return 0;
3025 }
3026
3027 /* Otherwise convert through a datetimestruct */
3028 if (convert_datetime_to_datetimestruct(src_meta, src_dt, &dts) < 0) {
3029 *dst_dt = NPY_DATETIME_NAT;
3030 return -1;
3031 }
3032 if (convert_datetimestruct_to_datetime(dst_meta, &dts, dst_dt) < 0) {
3033 *dst_dt = NPY_DATETIME_NAT;
3034 return -1;
3035 }
3036
3037 return 0;
3038}
3039
3040/*
3041 * Casts a single timedelta from having src_meta metadata into

Callers 2

Tested by

no test coverage detected