I think that here you should be using sklearn.utils.gen_even_slices.