@@ -324,19 +324,6 @@ static npy_float64 total_seconds(PyObject *td) {
324
324
return double_val ;
325
325
}
326
326
327
- static PyObject * get_item (PyObject * obj , Py_ssize_t i ) {
328
- PyObject * tmp = PyLong_FromSsize_t (i );
329
- PyObject * ret ;
330
-
331
- if (tmp == 0 ) {
332
- return 0 ;
333
- }
334
- ret = PyObject_GetItem (obj , tmp );
335
- Py_DECREF (tmp );
336
-
337
- return ret ;
338
- }
339
-
340
327
static char * PyBytesToUTF8 (JSOBJ _obj , JSONTypeContext * Py_UNUSED (tc ),
341
328
size_t * _outLen ) {
342
329
PyObject * obj = (PyObject * )_obj ;
@@ -704,18 +691,13 @@ void PdBlock_iterBegin(JSOBJ _obj, JSONTypeContext *tc) {
704
691
PdBlockContext * blkCtxt ;
705
692
NpyArrContext * npyarr ;
706
693
Py_ssize_t i ;
707
- PyArray_Descr * dtype ;
708
694
NpyIter * iter ;
709
695
NpyIter_IterNextFunc * iternext ;
710
696
npy_int64 * * dataptr ;
711
697
npy_int64 colIdx ;
712
698
npy_intp idx ;
713
699
714
700
PRINTMARK ();
715
-
716
- i = 0 ;
717
- blocks = NULL ;
718
- dtype = PyArray_DescrFromType (NPY_INT64 );
719
701
obj = (PyObject * )_obj ;
720
702
721
703
GET_TC (tc )-> iterGetName = GET_TC (tc )-> transpose
@@ -726,7 +708,7 @@ void PdBlock_iterBegin(JSOBJ _obj, JSONTypeContext *tc) {
726
708
if (!blkCtxt ) {
727
709
PyErr_NoMemory ();
728
710
GET_TC (tc )-> iterNext = NpyArr_iterNextNone ;
729
- goto BLKRET ;
711
+ return ;
730
712
}
731
713
GET_TC (tc )-> pdblock = blkCtxt ;
732
714
@@ -739,38 +721,38 @@ void PdBlock_iterBegin(JSOBJ _obj, JSONTypeContext *tc) {
739
721
blkCtxt -> cindices = NULL ;
740
722
741
723
GET_TC (tc )-> iterNext = NpyArr_iterNextNone ;
742
- goto BLKRET ;
724
+ return ;
743
725
}
744
726
745
727
blkCtxt -> npyCtxts =
746
728
PyObject_Malloc (sizeof (NpyArrContext * ) * blkCtxt -> ncols );
747
729
if (!blkCtxt -> npyCtxts ) {
748
730
PyErr_NoMemory ();
749
731
GET_TC (tc )-> iterNext = NpyArr_iterNextNone ;
750
- goto BLKRET ;
751
- }
752
- for (i = 0 ; i < blkCtxt -> ncols ; i ++ ) {
753
- blkCtxt -> npyCtxts [i ] = NULL ;
732
+ return ;
754
733
}
755
734
756
735
blkCtxt -> cindices = PyObject_Malloc (sizeof (int ) * blkCtxt -> ncols );
757
736
if (!blkCtxt -> cindices ) {
758
737
PyErr_NoMemory ();
759
738
GET_TC (tc )-> iterNext = NpyArr_iterNextNone ;
760
- goto BLKRET ;
739
+ return ;
761
740
}
762
741
763
742
blocks = get_sub_attr (obj , "_mgr" , "blocks" );
764
743
if (!blocks ) {
765
744
GET_TC (tc )-> iterNext = NpyArr_iterNextNone ;
766
- goto BLKRET ;
745
+ return ;
746
+ } else if (!PyTuple_Check (blocks )) {
747
+ PyErr_SetString (PyExc_TypeError , "blocks must be a tuple!" );
748
+ goto BLKRET ;
767
749
}
768
750
769
751
// force transpose so each NpyArrContext strides down its column
770
752
GET_TC (tc )-> transpose = 1 ;
771
753
772
754
for (i = 0 ; i < PyObject_Length (blocks ); i ++ ) {
773
- block = get_item (blocks , i );
755
+ block = PyTuple_GET_ITEM (blocks , i );
774
756
if (!block ) {
775
757
GET_TC (tc )-> iterNext = NpyArr_iterNextNone ;
776
758
goto BLKRET ;
@@ -779,31 +761,27 @@ void PdBlock_iterBegin(JSOBJ _obj, JSONTypeContext *tc) {
779
761
tmp = PyObject_CallMethod (block , "get_block_values_for_json" , NULL );
780
762
if (!tmp ) {
781
763
((JSONObjectEncoder * )tc -> encoder )-> errorMsg = "" ;
782
- Py_DECREF (block );
783
764
GET_TC (tc )-> iterNext = NpyArr_iterNextNone ;
784
765
goto BLKRET ;
785
766
}
786
767
787
768
values = PyArray_Transpose ((PyArrayObject * )tmp , NULL );
788
769
Py_DECREF (tmp );
789
770
if (!values ) {
790
- Py_DECREF (block );
791
771
GET_TC (tc )-> iterNext = NpyArr_iterNextNone ;
792
772
goto BLKRET ;
793
773
}
794
774
795
775
locs = (PyArrayObject * )get_sub_attr (block , "mgr_locs" , "as_array" );
796
776
if (!locs ) {
797
- Py_DECREF (block );
798
777
Py_DECREF (values );
799
778
GET_TC (tc )-> iterNext = NpyArr_iterNextNone ;
800
779
goto BLKRET ;
801
780
}
802
781
803
782
iter = NpyIter_New (locs , NPY_ITER_READONLY , NPY_KEEPORDER ,
804
- NPY_NO_CASTING , dtype );
783
+ NPY_NO_CASTING , NULL );
805
784
if (!iter ) {
806
- Py_DECREF (block );
807
785
Py_DECREF (values );
808
786
Py_DECREF (locs );
809
787
GET_TC (tc )-> iterNext = NpyArr_iterNextNone ;
@@ -812,7 +790,6 @@ void PdBlock_iterBegin(JSOBJ _obj, JSONTypeContext *tc) {
812
790
iternext = NpyIter_GetIterNext (iter , NULL );
813
791
if (!iternext ) {
814
792
NpyIter_Deallocate (iter );
815
- Py_DECREF (block );
816
793
Py_DECREF (values );
817
794
Py_DECREF (locs );
818
795
GET_TC (tc )-> iterNext = NpyArr_iterNextNone ;
@@ -846,15 +823,13 @@ void PdBlock_iterBegin(JSOBJ _obj, JSONTypeContext *tc) {
846
823
} while (iternext (iter ));
847
824
848
825
NpyIter_Deallocate (iter );
849
- Py_DECREF (block );
850
826
Py_DECREF (values );
851
827
Py_DECREF (locs );
852
828
}
853
829
GET_TC (tc )-> npyarr = blkCtxt -> npyCtxts [0 ];
854
830
855
831
BLKRET :
856
- Py_XDECREF (dtype );
857
- Py_XDECREF (blocks );
832
+ Py_DECREF (blocks );
858
833
}
859
834
860
835
void PdBlock_iterEnd (JSOBJ obj , JSONTypeContext * tc ) {
0 commit comments