Skip to content

Commit

Permalink
Backport PR pandas-dev#57379: Fix numpy-dev CI warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAyd authored and meeseeksmachine committed Feb 12, 2024
1 parent 947f5ae commit 28fd3fb
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions pandas/_libs/src/vendored/ujson/python/objToJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,15 @@ static void NpyArrPassThru_iterEnd(JSOBJ obj, JSONTypeContext *tc) {
npyarr->curdim--;
npyarr->dataptr -= npyarr->stride * npyarr->index[npyarr->stridedim];
npyarr->stridedim -= npyarr->inc;
npyarr->dim = PyArray_DIM(npyarr->array, npyarr->stridedim);
npyarr->stride = PyArray_STRIDE(npyarr->array, npyarr->stridedim);

if (!PyArray_Check(npyarr->array)) {
PyErr_SetString(PyExc_TypeError,
"NpyArrayPassThru_iterEnd received a non-array object");
return;
}
const PyArrayObject *arrayobj = (const PyArrayObject *)npyarr->array;
npyarr->dim = PyArray_DIM(arrayobj, npyarr->stridedim);
npyarr->stride = PyArray_STRIDE(arrayobj, npyarr->stridedim);
npyarr->dataptr += npyarr->stride;

NpyArr_freeItemValue(obj, tc);
Expand All @@ -467,12 +474,19 @@ static int NpyArr_iterNextItem(JSOBJ obj, JSONTypeContext *tc) {

NpyArr_freeItemValue(obj, tc);

if (PyArray_ISDATETIME(npyarr->array)) {
if (!PyArray_Check(npyarr->array)) {
PyErr_SetString(PyExc_TypeError,
"NpyArr_iterNextItem received a non-array object");
return 0;
}
PyArrayObject *arrayobj = (PyArrayObject *)npyarr->array;

if (PyArray_ISDATETIME(arrayobj)) {
GET_TC(tc)->itemValue = obj;
Py_INCREF(obj);
((PyObjectEncoder *)tc->encoder)->npyType = PyArray_TYPE(npyarr->array);
((PyObjectEncoder *)tc->encoder)->npyType = PyArray_TYPE(arrayobj);
// Also write the resolution (unit) of the ndarray
PyArray_Descr *dtype = PyArray_DESCR(npyarr->array);
PyArray_Descr *dtype = PyArray_DESCR(arrayobj);
((PyObjectEncoder *)tc->encoder)->valueUnit =
get_datetime_metadata_from_dtype(dtype).base;
((PyObjectEncoder *)tc->encoder)->npyValue = npyarr->dataptr;
Expand Down Expand Up @@ -505,8 +519,15 @@ static int NpyArr_iterNext(JSOBJ _obj, JSONTypeContext *tc) {

npyarr->curdim++;
npyarr->stridedim += npyarr->inc;
npyarr->dim = PyArray_DIM(npyarr->array, npyarr->stridedim);
npyarr->stride = PyArray_STRIDE(npyarr->array, npyarr->stridedim);
if (!PyArray_Check(npyarr->array)) {
PyErr_SetString(PyExc_TypeError,
"NpyArr_iterNext received a non-array object");
return 0;
}
const PyArrayObject *arrayobj = (const PyArrayObject *)npyarr->array;

npyarr->dim = PyArray_DIM(arrayobj, npyarr->stridedim);
npyarr->stride = PyArray_STRIDE(arrayobj, npyarr->stridedim);
npyarr->index[npyarr->stridedim] = 0;

((PyObjectEncoder *)tc->encoder)->npyCtxtPassthru = npyarr;
Expand Down Expand Up @@ -1610,7 +1631,14 @@ static void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
if (!values) {
goto INVALID;
}
pc->columnLabelsLen = PyArray_DIM(pc->newObj, 0);

if (!PyArray_Check(pc->newObj)) {
PyErr_SetString(PyExc_TypeError,
"Object_beginTypeContext received a non-array object");
goto INVALID;
}
const PyArrayObject *arrayobj = (const PyArrayObject *)pc->newObj;
pc->columnLabelsLen = PyArray_DIM(arrayobj, 0);
pc->columnLabels = NpyArr_encodeLabels((PyArrayObject *)values, enc,
pc->columnLabelsLen);
if (!pc->columnLabels) {
Expand Down

0 comments on commit 28fd3fb

Please sign in to comment.