@@ -4183,8 +4183,8 @@ typedef struct BlockIndexObject {
4183
4183
} BlockIndexObject ;
4184
4184
4185
4185
4186
- // Returns a new reference to tuple. Returns NULL on error.
4187
- static PyObject *
4186
+ // Returns a new reference to tuple. Returns NULL on error. Python already wraps negative numbers up to negative length when used in the sequence slot
4187
+ static inline PyObject *
4188
4188
AK_BI_item (BlockIndexObject * self , Py_ssize_t i ) {
4189
4189
if (!((size_t )i < (size_t )self -> bir_count )) {
4190
4190
PyErr_SetString (PyExc_IndexError , "index out of range" );
@@ -4194,6 +4194,16 @@ AK_BI_item(BlockIndexObject* self, Py_ssize_t i) {
4194
4194
return Py_BuildValue ("nn" , biri -> block , biri -> column ); // maybe NULL
4195
4195
}
4196
4196
4197
+ // Returns a new reference to tuple. Returns NULL on error. Supports negative numbers up to negative length.
4198
+ static inline PyObject *
4199
+ AK_BI_item_wraps (BlockIndexObject * self , Py_ssize_t i )
4200
+ {
4201
+ if (i < 0 ) {
4202
+ i = self -> bir_count + i ;
4203
+ }
4204
+ return AK_BI_item (self , i );
4205
+ }
4206
+
4197
4207
//------------------------------------------------------------------------------
4198
4208
// BI Iterator
4199
4209
static PyTypeObject BIIterType ;
@@ -4378,7 +4388,7 @@ BIIterSeq_iternext(BIIterSeqObject *self) {
4378
4388
return NULL ;
4379
4389
}
4380
4390
}
4381
- return AK_BI_item (self -> bi , t ); // return new ref
4391
+ return AK_BI_item_wraps (self -> bi , t ); // return new ref
4382
4392
}
4383
4393
4384
4394
static PyObject *
@@ -4557,7 +4567,6 @@ static PyTypeObject BIIterBooleanType = {
4557
4567
.tp_name = "arraykit.BlockIndexIteratorBoolean" ,
4558
4568
};
4559
4569
4560
-
4561
4570
//------------------------------------------------------------------------------
4562
4571
4563
4572
// NOTE: this constructor returns one of three different PyObject types. We do this to consolidate error reporting and type checks.
@@ -4628,7 +4637,6 @@ BIIterSelector_new(BlockIndexObject *bi,
4628
4637
pos += (step * (len - 1 ));
4629
4638
step *= -1 ;
4630
4639
}
4631
- // AK_DEBUG_MSG_OBJ("resolved slice", Py_BuildValue("nnnn", pos, stop, step, len));
4632
4640
}
4633
4641
else if (PyList_CheckExact (selector )) {
4634
4642
if (kind == BIIS_UNKNOWN ) {
@@ -4694,8 +4702,6 @@ BIIterSelector_new(BlockIndexObject *bi,
4694
4702
return NULL ;
4695
4703
}
4696
4704
4697
-
4698
-
4699
4705
//------------------------------------------------------------------------------
4700
4706
4701
4707
// Returns 0 on succes, -1 on error.
0 commit comments