* Recursively determines the metadata for an NPY_DATETIME dtype. * * Returns 0 on success, -1 on failure. */
| 3578 | * Returns 0 on success, -1 on failure. |
| 3579 | */ |
| 3580 | static int |
| 3581 | find_object_datetime64_meta(PyObject *obj, PyArray_DatetimeMetaData *meta) |
| 3582 | { |
| 3583 | if (PyArray_IsScalar(obj, Datetime)) { |
| 3584 | PyDatetimeScalarObject *dts = (PyDatetimeScalarObject *)obj; |
| 3585 | |
| 3586 | /* Combine it with 'meta' */ |
| 3587 | if (compute_datetime_metadata_greatest_common_divisor(meta, |
| 3588 | &dts->obmeta, meta, 0, 0) < 0) { |
| 3589 | return -1; |
| 3590 | } |
| 3591 | |
| 3592 | return 0; |
| 3593 | } |
| 3594 | /* String -> parse it to find out */ |
| 3595 | else if (PyBytes_Check(obj) || PyUnicode_Check(obj)) { |
| 3596 | npy_datetime tmp = 0; |
| 3597 | PyArray_DatetimeMetaData tmp_meta; |
| 3598 | |
| 3599 | tmp_meta.base = NPY_FR_ERROR; |
| 3600 | tmp_meta.num = 1; |
| 3601 | |
| 3602 | if (convert_pyobject_to_datetime(&tmp_meta, obj, |
| 3603 | NPY_UNSAFE_CASTING, &tmp) < 0) { |
| 3604 | /* If it's a value error, clear the error */ |
| 3605 | if (PyErr_Occurred() && |
| 3606 | PyErr_GivenExceptionMatches(PyErr_Occurred(), |
| 3607 | PyExc_ValueError)) { |
| 3608 | PyErr_Clear(); |
| 3609 | return 0; |
| 3610 | } |
| 3611 | /* Otherwise propagate the error */ |
| 3612 | else { |
| 3613 | return -1; |
| 3614 | } |
| 3615 | } |
| 3616 | |
| 3617 | /* Combine it with 'meta' */ |
| 3618 | if (compute_datetime_metadata_greatest_common_divisor(meta, |
| 3619 | &tmp_meta, meta, 0, 0) < 0) { |
| 3620 | return -1; |
| 3621 | } |
| 3622 | |
| 3623 | return 0; |
| 3624 | } |
| 3625 | /* Python datetime object -> 'us' */ |
| 3626 | else if (PyDateTime_Check(obj)) { |
| 3627 | PyArray_DatetimeMetaData tmp_meta; |
| 3628 | |
| 3629 | tmp_meta.base = NPY_FR_us; |
| 3630 | tmp_meta.num = 1; |
| 3631 | |
| 3632 | /* Combine it with 'meta' */ |
| 3633 | if (compute_datetime_metadata_greatest_common_divisor(meta, |
| 3634 | &tmp_meta, meta, 0, 0) < 0) { |
| 3635 | return -1; |
| 3636 | } |
| 3637 |
no test coverage detected