@@ -5304,6 +5304,7 @@ BlockIndex_register(BlockIndexObject *self, PyObject *value) {
53045304 Py_ssize_t alignment = PyArray_DIM (a , 0 );
53055305 if (self -> row_count == -1 ) {
53065306 self -> row_count = alignment ;
5307+ self -> shape_recache = true; // setting rows, must recache shape
53075308 }
53085309 else if (self -> row_count != alignment ) {
53095310 PyErr_Format (ErrorInitTypeBlocks ,
@@ -5422,12 +5423,17 @@ BlockIndex_setstate(BlockIndexObject *self, PyObject *state)
54225423//------------------------------------------------------------------------------
54235424// getters
54245425
5426+ // Never expose a negative row value to the caller
5427+ #define AK_BI_ROWS (rows ) ((rows) < 0 ? 0 : (rows))
5428+
54255429static PyObject *
54265430BlockIndex_shape_getter (BlockIndexObject * self , void * Py_UNUSED (closure ))
54275431{
54285432 if (self -> shape == NULL || self -> shape_recache ) {
54295433 Py_XDECREF (self -> shape ); // get rid of old if it exists
5430- self -> shape = AK_build_pair_ssize_t (self -> row_count , self -> bir_count );
5434+ self -> shape = AK_build_pair_ssize_t (
5435+ AK_BI_ROWS (self -> row_count ),
5436+ self -> bir_count );
54315437 }
54325438 // shape is not null and shape_recache is false
54335439 Py_INCREF (self -> shape ); // for caller
@@ -5437,7 +5443,7 @@ BlockIndex_shape_getter(BlockIndexObject *self, void* Py_UNUSED(closure))
54375443
54385444static PyObject *
54395445BlockIndex_rows_getter (BlockIndexObject * self , void * Py_UNUSED (closure )){
5440- return PyLong_FromSsize_t (self -> row_count );
5446+ return PyLong_FromSsize_t (AK_BI_ROWS ( self -> row_count ) );
54415447}
54425448
54435449static PyObject *
0 commit comments