@@ -4114,7 +4114,7 @@ get_new_indexers_and_screen(PyObject *Py_UNUSED(m), PyObject *args, PyObject *kw
41144114//------------------------------------------------------------------------------
41154115
41164116static PyTypeObject BlockIndexType ;
4117- static PyObject * ErrorInitBlocks ;
4117+ static PyObject * ErrorInitTypeBlocks ;
41184118
41194119// NOTE: we use platform size types here, which are appropriate for the values, but might pose issues if trying to pass pickles between 32 and 64 bit machines.
41204120typedef struct BlockIndexRecord {
@@ -4777,18 +4777,18 @@ BlockIndex_repr(BlockIndexObject *self) {
47774777 dt );
47784778}
47794779
4780- // Returns NULL on error, None otherwise . This checks and raises on non-array inputs, dimensions other than 1 or 2.
4780+ // Returns NULL on error, True if the block should be reatained, False if the block has zero columns and should not be retained . This checks and raises on non-array inputs, dimensions other than 1 or 2, and mis-aligned columns .
47814781static PyObject *
47824782BlockIndex_register (BlockIndexObject * self , PyObject * value ) {
47834783 if (!PyArray_Check (value )) {
4784- PyErr_Format (ErrorInitBlocks , "Found non-array block: %R" , value );
4784+ PyErr_Format (ErrorInitTypeBlocks , "Found non-array block: %R" , value );
47854785 return NULL ;
47864786 }
47874787 PyArrayObject * a = (PyArrayObject * )value ;
47884788 int ndim = PyArray_NDIM (a );
47894789
47904790 if (ndim < 1 || ndim > 2 ) {
4791- PyErr_Format (ErrorInitBlocks , "Array block has invalid dimensions: %i" , ndim );
4791+ PyErr_Format (ErrorInitTypeBlocks , "Array block has invalid dimensions: %i" , ndim );
47924792 return NULL ;
47934793 }
47944794 Py_ssize_t increment = ndim == 1 ? 1 : PyArray_DIM (a , 1 );
@@ -4799,13 +4799,17 @@ BlockIndex_register(BlockIndexObject *self, PyObject *value) {
47994799 self -> row_count = alignment ;
48004800 }
48014801 else if (self -> row_count != alignment ) {
4802- PyErr_Format (ErrorInitBlocks ,
4802+ PyErr_Format (ErrorInitTypeBlocks ,
48034803 "Array block has unaligned row count: found %i, expected %i" ,
48044804 alignment ,
48054805 self -> row_count );
48064806 return NULL ;
48074807 }
48084808
4809+ if (increment == 0 ) {
4810+ Py_RETURN_FALSE ;
4811+ }
4812+
48094813 PyArray_Descr * dt = PyArray_DESCR (a ); // borrowed ref
48104814 if (self -> dtype == NULL ) {
48114815 Py_INCREF ((PyObject * )dt );
@@ -4829,7 +4833,7 @@ BlockIndex_register(BlockIndexObject *self, PyObject *value) {
48294833 self -> bir_count ++ ;
48304834 }
48314835 self -> block_count ++ ;
4832- Py_RETURN_NONE ;
4836+ Py_RETURN_TRUE ;
48334837}
48344838
48354839
@@ -4942,6 +4946,7 @@ BlockIndex_iter(BlockIndexObject* self) {
49424946
49434947static PyObject *
49444948BlockIndex_shape_getter (BlockIndexObject * self , void * Py_UNUSED (closure )){
4949+ // NOTE: this could be cached
49454950 return Py_BuildValue ("nn" , self -> row_count , self -> bir_count );
49464951}
49474952
@@ -5395,12 +5400,12 @@ PyInit__arraykit(void)
53955400{
53965401 import_array ();
53975402
5398- ErrorInitBlocks = PyErr_NewExceptionWithDoc (
5399- "arraykit.ErrorInitBlocks " ,
5403+ ErrorInitTypeBlocks = PyErr_NewExceptionWithDoc (
5404+ "arraykit.ErrorInitTypeBlocks " ,
54005405 "RuntimeError error in block initialization." ,
54015406 PyExc_RuntimeError ,
54025407 NULL );
5403- if (ErrorInitBlocks == NULL ) {
5408+ if (ErrorInitTypeBlocks == NULL ) {
54045409 return NULL ;
54055410 }
54065411
@@ -5426,7 +5431,7 @@ PyInit__arraykit(void)
54265431 PyModule_AddObject (m , "BlockIndex" , (PyObject * ) & BlockIndexType ) ||
54275432 PyModule_AddObject (m , "ArrayGO" , (PyObject * ) & ArrayGOType ) ||
54285433 PyModule_AddObject (m , "deepcopy" , deepcopy ) ||
5429- PyModule_AddObject (m , "ErrorInitBlocks " , ErrorInitBlocks )
5434+ PyModule_AddObject (m , "ErrorInitTypeBlocks " , ErrorInitTypeBlocks )
54305435 ){
54315436 Py_DECREF (deepcopy );
54325437 Py_XDECREF (m );
0 commit comments