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

Function raise_if_datetime64_metadata_cast_error

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

* Tests whether a datetime64 can be cast from the source metadata * to the destination metadata according to the specified casting rule. * * Returns -1 if an exception was raised, 0 otherwise. */

Source from the content-addressed store, hash-verified

1444 * Returns -1 if an exception was raised, 0 otherwise.
1445 */
1446NPY_NO_EXPORT int
1447raise_if_datetime64_metadata_cast_error(char *object_type,
1448 PyArray_DatetimeMetaData *src_meta,
1449 PyArray_DatetimeMetaData *dst_meta,
1450 NPY_CASTING casting)
1451{
1452 if (can_cast_datetime64_metadata(src_meta, dst_meta, casting)) {
1453 return 0;
1454 }
1455 else {
1456 PyObject *src = metastr_to_unicode(src_meta, 0);
1457 if (src == NULL) {
1458 return -1;
1459 }
1460 PyObject *dst = metastr_to_unicode(dst_meta, 0);
1461 if (dst == NULL) {
1462 Py_DECREF(src);
1463 return -1;
1464 }
1465 PyErr_Format(PyExc_TypeError,
1466 "Cannot cast %s from metadata %S to %S according to the rule %s",
1467 object_type, src, dst, npy_casting_to_string(casting));
1468 Py_DECREF(src);
1469 Py_DECREF(dst);
1470 return -1;
1471 }
1472}
1473
1474/*
1475 * Tests whether a timedelta64 can be cast from the source metadata

Callers 1

Calls 3

metastr_to_unicodeFunction · 0.85
npy_casting_to_stringFunction · 0.85

Tested by

no test coverage detected