@@ -1306,14 +1306,7 @@ char **NpyArr_encodeLabels(PyArrayObject *labels, PyObjectEncoder *enc,
1306
1306
NPY_DATETIMEUNIT dateUnit = NPY_FR_ns ;
1307
1307
if (PyTypeNum_ISDATETIME (type_num )) {
1308
1308
is_datetimelike = 1 ;
1309
- PyArray_VectorUnaryFunc * castfunc =
1310
- PyArray_GetCastFunc (PyArray_DescrFromType (type_num ), NPY_INT64 );
1311
- if (!castfunc ) {
1312
- PyErr_Format (PyExc_ValueError ,
1313
- "Cannot cast numpy dtype %d to long" ,
1314
- enc -> npyType );
1315
- }
1316
- castfunc (dataptr , & i8date , 1 , NULL , NULL );
1309
+ i8date = * (npy_int64 * )dataptr ;
1317
1310
dateUnit = get_datetime_metadata_from_dtype (dtype ).base ;
1318
1311
} else if (PyDate_Check (item ) || PyDelta_Check (item )) {
1319
1312
is_datetimelike = 1 ;
@@ -1444,24 +1437,23 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
1444
1437
return ;
1445
1438
}
1446
1439
1447
- pc = createTypeContext ();
1448
- if (!pc ) {
1449
- tc -> type = JT_INVALID ;
1450
- return ;
1451
- }
1452
- tc -> prv = pc ;
1440
+ pc = createTypeContext ();
1441
+ if (!pc ) {
1442
+ tc -> type = JT_INVALID ;
1443
+ return ;
1444
+ }
1445
+ tc -> prv = pc ;
1453
1446
1454
- if (PyTypeNum_ISDATETIME (enc -> npyType )) {
1455
- int64_t longVal ;
1456
- PyArray_VectorUnaryFunc * castfunc =
1457
- PyArray_GetCastFunc (PyArray_DescrFromType (enc -> npyType ), NPY_INT64 );
1458
- if (!castfunc ) {
1459
- PyErr_Format (PyExc_ValueError , "Cannot cast numpy dtype %d to long" ,
1460
- enc -> npyType );
1461
- }
1462
- castfunc (enc -> npyValue , & longVal , 1 , NULL , NULL );
1463
- if (longVal == get_nat ()) {
1464
- tc -> type = JT_NULL ;
1447
+ if (PyTypeNum_ISDATETIME (enc -> npyType )) {
1448
+ int64_t longVal ;
1449
+
1450
+ longVal = * (npy_int64 * )enc -> npyValue ;
1451
+ if (longVal == get_nat ()) {
1452
+ tc -> type = JT_NULL ;
1453
+ } else {
1454
+ if (enc -> datetimeIso ) {
1455
+ if (enc -> npyType == NPY_TIMEDELTA ) {
1456
+ pc -> PyTypeToUTF8 = NpyTimeDeltaToIsoCallback ;
1465
1457
} else {
1466
1458
if (enc -> datetimeIso ) {
1467
1459
if (enc -> npyType == NPY_TIMEDELTA ) {
0 commit comments