Skip to content

Commit 6d1b07f

Browse files
authored
CLN: Get rid of PyArray_GetCastFunc (#56114)
* CLN: Get rid of PyArray_GetCastFunc * remove old code * simplify as per suggestion * delete dead code * simplify again * Update objToJSON.c
1 parent 6971c9c commit 6d1b07f

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

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

+3-14
Original file line numberDiff line numberDiff line change
@@ -1280,13 +1280,7 @@ 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+
i8date = *(npy_int64 *)dataptr;
12901284
dateUnit = get_datetime_metadata_from_dtype(dtype).base;
12911285
} else if (PyDate_Check(item) || PyDelta_Check(item)) {
12921286
is_datetimelike = 1;
@@ -1425,13 +1419,8 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
14251419

14261420
if (PyTypeNum_ISDATETIME(enc->npyType)) {
14271421
int64_t longVal;
1428-
PyArray_VectorUnaryFunc *castfunc =
1429-
PyArray_GetCastFunc(PyArray_DescrFromType(enc->npyType), NPY_INT64);
1430-
if (!castfunc) {
1431-
PyErr_Format(PyExc_ValueError, "Cannot cast numpy dtype %d to long",
1432-
enc->npyType);
1433-
}
1434-
castfunc(enc->npyValue, &longVal, 1, NULL, NULL);
1422+
1423+
longVal = *(npy_int64 *)enc->npyValue;
14351424
if (longVal == get_nat()) {
14361425
tc->type = JT_NULL;
14371426
} else {

0 commit comments

Comments
 (0)