@@ -1280,13 +1280,10 @@ char **NpyArr_encodeLabels(PyArrayObject *labels, PyObjectEncoder *enc,
1280
1280
NPY_DATETIMEUNIT dateUnit = NPY_FR_ns ;
1281
1281
if (PyTypeNum_ISDATETIME (type_num )) {
1282
1282
is_datetimelike = 1 ;
1283
- PyArray_VectorUnaryFunc * castfunc =
1284
- PyArray_GetCastFunc (PyArray_DescrFromType (type_num ), NPY_INT64 );
1285
- if (!castfunc ) {
1286
- PyErr_Format (PyExc_ValueError , "Cannot cast numpy dtype %d to long" ,
1287
- enc -> npyType );
1288
- }
1289
- castfunc (dataptr , & i8date , 1 , NULL , NULL );
1283
+ PyObject * scalarItem = PyArray_ToScalar (dataptr , labels );
1284
+ PyArray_CastScalarToCtype (scalarItem , & i8date ,
1285
+ PyArray_DescrFromType (NPY_INT64 ));
1286
+ Py_DECREF (scalarItem );
1290
1287
dateUnit = get_datetime_metadata_from_dtype (dtype ).base ;
1291
1288
} else if (PyDate_Check (item ) || PyDelta_Check (item )) {
1292
1289
is_datetimelike = 1 ;
@@ -1432,6 +1429,17 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
1432
1429
enc -> npyType );
1433
1430
}
1434
1431
castfunc (enc -> npyValue , & longVal , 1 , NULL , NULL );
1432
+
1433
+ // PyObject *scalar = PyArray_ToScalar(enc->npyValue,
1434
+ // enc->npyCtxtPassthru->array);
1435
+ // PyArray_Scalar(enc->npyValue,
1436
+ // PyArray_DescrFromType(enc->npyType),
1437
+ // NULL);
1438
+ // PyObject_Print(scalar, stdout, 0);
1439
+ // longVal = PyArray_CastScalarToCtype(scalar, &longVal,
1440
+ // PyArray_DescrFromType(NPY_INT64));
1441
+ // printf("%lld\n", longVal);
1442
+ // Py_DECREF(scalar);
1435
1443
if (longVal == get_nat ()) {
1436
1444
tc -> type = JT_NULL ;
1437
1445
} else {
@@ -1532,7 +1540,6 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
1532
1540
1533
1541
PyArray_Descr * outcode = PyArray_DescrFromType (NPY_INT64 );
1534
1542
PyArray_CastScalarToCtype (obj , & longVal , outcode );
1535
- Py_DECREF (outcode );
1536
1543
1537
1544
if (enc -> datetimeIso ) {
1538
1545
GET_TC (tc )-> longValue = longVal ;
0 commit comments