Skip to content

Commit 9511c13

Browse files
committed
CLN: Get rid of PyArray_GetCastFunc
1 parent 4514636 commit 9511c13

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

pandas/_libs/src/vendored/ujson/python/objToJSON.c

+11-8
Original file line numberDiff line numberDiff line change
@@ -1280,13 +1280,10 @@ char **NpyArr_encodeLabels(PyArrayObject *labels, PyObjectEncoder *enc,
12801280
NPY_DATETIMEUNIT dateUnit = NPY_FR_ns;
12811281
if (PyTypeNum_ISDATETIME(type_num)) {
12821282
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);
12901287
dateUnit = get_datetime_metadata_from_dtype(dtype).base;
12911288
} else if (PyDate_Check(item) || PyDelta_Check(item)) {
12921289
is_datetimelike = 1;
@@ -1432,6 +1429,13 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
14321429
enc->npyType);
14331430
}
14341431
castfunc(enc->npyValue, &longVal, 1, NULL, NULL);
1432+
1433+
// PyObject *scalar = PyArray_ToScalar(enc->npyValue,
1434+
// enc->npyCtxtPassthru->array); //PyArray_Scalar(enc->npyValue,
1435+
// PyArray_DescrFromType(enc->npyType), NULL); PyObject_Print(scalar,
1436+
// stdout, 0); longVal = PyArray_CastScalarToCtype(scalar, &longVal,
1437+
// PyArray_DescrFromType(NPY_INT64)); printf("%lld\n", longVal);
1438+
// Py_DECREF(scalar);
14351439
if (longVal == get_nat()) {
14361440
tc->type = JT_NULL;
14371441
} else {
@@ -1532,7 +1536,6 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
15321536

15331537
PyArray_Descr *outcode = PyArray_DescrFromType(NPY_INT64);
15341538
PyArray_CastScalarToCtype(obj, &longVal, outcode);
1535-
Py_DECREF(outcode);
15361539

15371540
if (enc->datetimeIso) {
15381541
GET_TC(tc)->longValue = longVal;

0 commit comments

Comments
 (0)