* This is the Python-exposed datetime_as_string function. */
| 1331 | * This is the Python-exposed datetime_as_string function. |
| 1332 | */ |
| 1333 | NPY_NO_EXPORT PyObject * |
| 1334 | array_datetime_as_string(PyObject *NPY_UNUSED(self), PyObject *args, |
| 1335 | PyObject *kwds) |
| 1336 | { |
| 1337 | PyObject *arr_in = NULL, *unit_in = NULL, *timezone_obj = NULL; |
| 1338 | NPY_DATETIMEUNIT unit; |
| 1339 | NPY_CASTING casting = NPY_SAME_KIND_CASTING; |
| 1340 | |
| 1341 | int local = 0; |
| 1342 | int utc = 0; |
| 1343 | PyArray_DatetimeMetaData *meta; |
| 1344 | int strsize; |
| 1345 | |
| 1346 | PyArrayObject *ret = NULL; |
| 1347 | |
| 1348 | NpyIter *iter = NULL; |
| 1349 | PyArrayObject *op[2] = {NULL, NULL}; |
| 1350 | PyArray_Descr *op_dtypes[2] = {NULL, NULL}; |
| 1351 | npy_uint32 flags, op_flags[2]; |
| 1352 | |
| 1353 | static char *kwlist[] = {"arr", "unit", "timezone", "casting", NULL}; |
| 1354 | |
| 1355 | if(!PyArg_ParseTupleAndKeywords(args, kwds, |
| 1356 | "O|OOO&:datetime_as_string", kwlist, |
| 1357 | &arr_in, |
| 1358 | &unit_in, |
| 1359 | &timezone_obj, |
| 1360 | &PyArray_CastingConverter, &casting)) { |
| 1361 | return NULL; |
| 1362 | } |
| 1363 | |
| 1364 | /* Claim a reference to timezone for later */ |
| 1365 | Py_XINCREF(timezone_obj); |
| 1366 | |
| 1367 | op[0] = (PyArrayObject *)PyArray_FROM_O(arr_in); |
| 1368 | if (op[0] == NULL) { |
| 1369 | goto fail; |
| 1370 | } |
| 1371 | if (PyArray_DESCR(op[0])->type_num != NPY_DATETIME) { |
| 1372 | PyErr_SetString(PyExc_TypeError, |
| 1373 | "input must have type NumPy datetime"); |
| 1374 | goto fail; |
| 1375 | } |
| 1376 | |
| 1377 | /* Get the datetime metadata */ |
| 1378 | meta = get_datetime_metadata_from_dtype(PyArray_DESCR(op[0])); |
| 1379 | if (meta == NULL) { |
| 1380 | goto fail; |
| 1381 | } |
| 1382 | |
| 1383 | /* Use the metadata's unit for printing by default */ |
| 1384 | unit = meta->base; |
| 1385 | |
| 1386 | /* Parse the input unit if provided */ |
| 1387 | if (unit_in != NULL && unit_in != Py_None) { |
| 1388 | PyObject *strobj; |
| 1389 | |
| 1390 | if (PyBytes_Check(unit_in)) { |
nothing calls this directly
no test coverage detected