@@ -48,10 +48,9 @@ Numeric decoder derived from from TCL library
4848#include <../../../tslibs/src/datetime/np_datetime_strings.h>
4949#include "datetime.h"
5050
51- static PyObject * type_decimal ;
52-
5351#define NPY_JSON_BUFSIZE 32768
5452
53+ static PyTypeObject * type_decimal ;
5554static PyTypeObject * cls_dataframe ;
5655static PyTypeObject * cls_series ;
5756static PyTypeObject * cls_index ;
@@ -154,8 +153,8 @@ void *initObjToJSON(void)
154153 PyObject * mod_pandas ;
155154 PyObject * mod_nattype ;
156155 PyObject * mod_decimal = PyImport_ImportModule ("decimal" );
157- type_decimal = PyObject_GetAttrString ( mod_decimal , "Decimal" );
158- Py_INCREF ( type_decimal );
156+ type_decimal =
157+ ( PyTypeObject * ) PyObject_GetAttrString ( mod_decimal , "Decimal" );
159158 Py_DECREF (mod_decimal );
160159
161160 PyDateTime_IMPORT ;
@@ -628,44 +627,39 @@ void NpyArr_iterBegin(JSOBJ _obj, JSONTypeContext *tc) {
628627 obj = (PyArrayObject * )_obj ;
629628 }
630629
631- if (PyArray_SIZE (obj ) < 0 ) {
632- PRINTMARK ();
633- GET_TC (tc )-> iterNext = NpyArr_iterNextNone ;
630+ PRINTMARK ();
631+ npyarr = PyObject_Malloc (sizeof (NpyArrContext ));
632+ GET_TC (tc )-> npyarr = npyarr ;
633+
634+ if (!npyarr ) {
635+ PyErr_NoMemory ();
636+ GET_TC (tc )-> iterNext = NpyArr_iterNextNone ;
637+ return ;
638+ }
639+
640+ npyarr -> array = (PyObject * )obj ;
641+ npyarr -> getitem = (PyArray_GetItemFunc * )PyArray_DESCR (obj )-> f -> getitem ;
642+ npyarr -> dataptr = PyArray_DATA (obj );
643+ npyarr -> ndim = PyArray_NDIM (obj ) - 1 ;
644+ npyarr -> curdim = 0 ;
645+ npyarr -> type_num = PyArray_DESCR (obj )-> type_num ;
646+
647+ if (GET_TC (tc )-> transpose ) {
648+ npyarr -> dim = PyArray_DIM (obj , npyarr -> ndim );
649+ npyarr -> stride = PyArray_STRIDE (obj , npyarr -> ndim );
650+ npyarr -> stridedim = npyarr -> ndim ;
651+ npyarr -> index [npyarr -> ndim ] = 0 ;
652+ npyarr -> inc = -1 ;
634653 } else {
635- PRINTMARK ();
636- npyarr = PyObject_Malloc (sizeof (NpyArrContext ));
637- GET_TC (tc )-> npyarr = npyarr ;
638-
639- if (!npyarr ) {
640- PyErr_NoMemory ();
641- GET_TC (tc )-> iterNext = NpyArr_iterNextNone ;
642- return ;
643- }
644-
645- npyarr -> array = (PyObject * )obj ;
646- npyarr -> getitem = (PyArray_GetItemFunc * )PyArray_DESCR (obj )-> f -> getitem ;
647- npyarr -> dataptr = PyArray_DATA (obj );
648- npyarr -> ndim = PyArray_NDIM (obj ) - 1 ;
649- npyarr -> curdim = 0 ;
650- npyarr -> type_num = PyArray_DESCR (obj )-> type_num ;
651-
652- if (GET_TC (tc )-> transpose ) {
653- npyarr -> dim = PyArray_DIM (obj , npyarr -> ndim );
654- npyarr -> stride = PyArray_STRIDE (obj , npyarr -> ndim );
655- npyarr -> stridedim = npyarr -> ndim ;
656- npyarr -> index [npyarr -> ndim ] = 0 ;
657- npyarr -> inc = -1 ;
658- } else {
659- npyarr -> dim = PyArray_DIM (obj , 0 );
660- npyarr -> stride = PyArray_STRIDE (obj , 0 );
661- npyarr -> stridedim = 0 ;
662- npyarr -> index [0 ] = 0 ;
663- npyarr -> inc = 1 ;
664- }
665-
666- npyarr -> columnLabels = GET_TC (tc )-> columnLabels ;
667- npyarr -> rowLabels = GET_TC (tc )-> rowLabels ;
654+ npyarr -> dim = PyArray_DIM (obj , 0 );
655+ npyarr -> stride = PyArray_STRIDE (obj , 0 );
656+ npyarr -> stridedim = 0 ;
657+ npyarr -> index [0 ] = 0 ;
658+ npyarr -> inc = 1 ;
668659 }
660+
661+ npyarr -> columnLabels = GET_TC (tc )-> columnLabels ;
662+ npyarr -> rowLabels = GET_TC (tc )-> rowLabels ;
669663}
670664
671665void NpyArr_iterEnd (JSOBJ obj , JSONTypeContext * tc ) {
@@ -1750,17 +1744,6 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
17501744 goto INVALID ;
17511745 }
17521746
1753- return ;
1754- } else if (PyLong_Check (obj )) {
1755- PRINTMARK ();
1756-
1757- #ifdef _LP64
1758- pc -> PyTypeToJSON = PyIntToINT64 ;
1759- tc -> type = JT_LONG ;
1760- #else
1761- pc -> PyTypeToJSON = PyIntToINT32 ;
1762- tc -> type = JT_INT ;
1763- #endif
17641747 return ;
17651748 } else if (PyFloat_Check (obj )) {
17661749 PRINTMARK ();
@@ -1782,7 +1765,7 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
17821765 pc -> PyTypeToJSON = PyUnicodeToUTF8 ;
17831766 tc -> type = JT_UTF8 ;
17841767 return ;
1785- } else if (PyObject_IsInstance (obj , type_decimal )) {
1768+ } else if (PyObject_TypeCheck (obj , type_decimal )) {
17861769 PRINTMARK ();
17871770 pc -> PyTypeToJSON = PyFloatToDOUBLE ;
17881771 tc -> type = JT_DOUBLE ;
0 commit comments