I think this whole function can be implemented much more simply with `concatenate`:

```python
indices = np.concatenate([X.indices[:m_ptr1], X.indices[n_ptr1:n_ptr2], X.indices[m_ptr2:n_ptr1], X.indices[n_ptr2:]])
data = np.concatenate(...)

X.indptr = np.concatenate(...)
X.indices = indices
X.data = data
```