Skip to content

Commit

Permalink
Backport PR #56114: CLN: Get rid of PyArray_GetCastFunc (#56313)
Browse files Browse the repository at this point in the history
* Backport PR #56114: CLN: Get rid of PyArray_GetCastFunc

* fix bad indent?

* remove more unintended changes
  • Loading branch information
lithomas1 authored Dec 4, 2023
1 parent f99a1fc commit 15376f8
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions pandas/_libs/src/vendored/ujson/python/objToJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -1306,14 +1306,7 @@ char **NpyArr_encodeLabels(PyArrayObject *labels, PyObjectEncoder *enc,
NPY_DATETIMEUNIT dateUnit = NPY_FR_ns;
if (PyTypeNum_ISDATETIME(type_num)) {
is_datetimelike = 1;
PyArray_VectorUnaryFunc *castfunc =
PyArray_GetCastFunc(PyArray_DescrFromType(type_num), NPY_INT64);
if (!castfunc) {
PyErr_Format(PyExc_ValueError,
"Cannot cast numpy dtype %d to long",
enc->npyType);
}
castfunc(dataptr, &i8date, 1, NULL, NULL);
i8date = *(npy_int64 *)dataptr;
dateUnit = get_datetime_metadata_from_dtype(dtype).base;
} else if (PyDate_Check(item) || PyDelta_Check(item)) {
is_datetimelike = 1;
Expand Down Expand Up @@ -1453,13 +1446,8 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {

if (PyTypeNum_ISDATETIME(enc->npyType)) {
int64_t longVal;
PyArray_VectorUnaryFunc *castfunc =
PyArray_GetCastFunc(PyArray_DescrFromType(enc->npyType), NPY_INT64);
if (!castfunc) {
PyErr_Format(PyExc_ValueError, "Cannot cast numpy dtype %d to long",
enc->npyType);
}
castfunc(enc->npyValue, &longVal, 1, NULL, NULL);

longVal = *(npy_int64 *)enc->npyValue;
if (longVal == get_nat()) {
tc->type = JT_NULL;
} else {
Expand Down

0 comments on commit 15376f8

Please sign in to comment.