Skip to content

Commit 1e266f2

Browse files
authored
cleaned up ujson initialization (#41864)
1 parent 3f28015 commit 1e266f2

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ Numeric decoder derived from from TCL library
3535
* Copyright (c) 1988-1993 The Regents of the University of California.
3636
* Copyright (c) 1994 Sun Microsystems, Inc.
3737
*/
38-
#define PY_ARRAY_UNIQUE_SYMBOL UJSON_NUMPY
3938

4039
#define PY_SSIZE_T_CLEAN
4140
#include <Python.h>
4241
#include <math.h>
42+
43+
#define NO_IMPORT_ARRAY
44+
#define PY_ARRAY_UNIQUE_SYMBOL UJSON_NUMPY
4345
#include <numpy/arrayobject.h>
4446
#include <numpy/arrayscalars.h>
4547
#include <numpy/ndarraytypes.h>
@@ -178,8 +180,6 @@ void *initObjToJSON(void) {
178180
Py_DECREF(mod_natype);
179181
}
180182

181-
/* Initialise numpy API */
182-
import_array();
183183
// GH 31463
184184
return NULL;
185185
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Numeric decoder derived from from TCL library
3838
#include "version.h"
3939
#define PY_SSIZE_T_CLEAN
4040
#include <Python.h>
41+
#define PY_ARRAY_UNIQUE_SYMBOL UJSON_NUMPY
42+
#include "numpy/arrayobject.h"
4143

4244
/* objToJSON */
4345
PyObject *objToJSON(PyObject *self, PyObject *args, PyObject *kwargs);
@@ -73,6 +75,7 @@ static PyModuleDef moduledef = {
7375

7476

7577
PyMODINIT_FUNC PyInit_json(void) {
78+
import_array()
7679
initObjToJSON(); // TODO(username): clean up, maybe via tp_free?
7780
return PyModuleDef_Init(&moduledef);
7881
}

0 commit comments

Comments
 (0)