@@ -48,10 +48,9 @@ Numeric decoder derived from from TCL library
48
48
#include <../../../tslibs/src/datetime/np_datetime_strings.h>
49
49
#include "datetime.h"
50
50
51
- static PyObject * type_decimal ;
52
-
53
51
#define NPY_JSON_BUFSIZE 32768
54
52
53
+ static PyTypeObject * type_decimal ;
55
54
static PyTypeObject * cls_dataframe ;
56
55
static PyTypeObject * cls_series ;
57
56
static PyTypeObject * cls_index ;
@@ -154,8 +153,8 @@ void *initObjToJSON(void)
154
153
PyObject * mod_pandas ;
155
154
PyObject * mod_nattype ;
156
155
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" );
159
158
Py_DECREF (mod_decimal );
160
159
161
160
PyDateTime_IMPORT ;
@@ -628,44 +627,39 @@ void NpyArr_iterBegin(JSOBJ _obj, JSONTypeContext *tc) {
628
627
obj = (PyArrayObject * )_obj ;
629
628
}
630
629
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 ;
634
653
} 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 ;
668
659
}
660
+
661
+ npyarr -> columnLabels = GET_TC (tc )-> columnLabels ;
662
+ npyarr -> rowLabels = GET_TC (tc )-> rowLabels ;
669
663
}
670
664
671
665
void NpyArr_iterEnd (JSOBJ obj , JSONTypeContext * tc ) {
@@ -1750,17 +1744,6 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
1750
1744
goto INVALID ;
1751
1745
}
1752
1746
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
1764
1747
return ;
1765
1748
} else if (PyFloat_Check (obj )) {
1766
1749
PRINTMARK ();
@@ -1782,7 +1765,7 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
1782
1765
pc -> PyTypeToJSON = PyUnicodeToUTF8 ;
1783
1766
tc -> type = JT_UTF8 ;
1784
1767
return ;
1785
- } else if (PyObject_IsInstance (obj , type_decimal )) {
1768
+ } else if (PyObject_TypeCheck (obj , type_decimal )) {
1786
1769
PRINTMARK ();
1787
1770
pc -> PyTypeToJSON = PyFloatToDOUBLE ;
1788
1771
tc -> type = JT_DOUBLE ;
0 commit comments