@@ -5304,6 +5304,7 @@ BlockIndex_register(BlockIndexObject *self, PyObject *value) {
5304
5304
Py_ssize_t alignment = PyArray_DIM (a , 0 );
5305
5305
if (self -> row_count == -1 ) {
5306
5306
self -> row_count = alignment ;
5307
+ self -> shape_recache = true; // setting rows, must recache shape
5307
5308
}
5308
5309
else if (self -> row_count != alignment ) {
5309
5310
PyErr_Format (ErrorInitTypeBlocks ,
@@ -5422,12 +5423,17 @@ BlockIndex_setstate(BlockIndexObject *self, PyObject *state)
5422
5423
//------------------------------------------------------------------------------
5423
5424
// getters
5424
5425
5426
+ // Never expose a negative row value to the caller
5427
+ #define AK_BI_ROWS (rows ) ((rows) < 0 ? 0 : (rows))
5428
+
5425
5429
static PyObject *
5426
5430
BlockIndex_shape_getter (BlockIndexObject * self , void * Py_UNUSED (closure ))
5427
5431
{
5428
5432
if (self -> shape == NULL || self -> shape_recache ) {
5429
5433
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 );
5431
5437
}
5432
5438
// shape is not null and shape_recache is false
5433
5439
Py_INCREF (self -> shape ); // for caller
@@ -5437,7 +5443,7 @@ BlockIndex_shape_getter(BlockIndexObject *self, void* Py_UNUSED(closure))
5437
5443
5438
5444
static PyObject *
5439
5445
BlockIndex_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 ) );
5441
5447
}
5442
5448
5443
5449
static PyObject *
0 commit comments