The index error is raised, since an index of 2512 is invalid for a shape of 2512, which would accept indices in [0, 2511], so you would have to check how this index is created and if you could clip it to the valid range.