I’m not sure what you are trying to fix.
If you are manually setting some target indices to -1, which is invalid in the default setup, you have to use ignore_index=-1, since otherwise the expected error will be raised.