FIX ValueError was not being raised

len(indptr) is always greater that 0 because its initialized with non-empty list.
Because of that this branch is never taken and the ValueError never raised.

Aditionaly, (as VirgileFritsch) suggested the next "if" was subsumed in the "else" of the first.