sklearn.utils.check_arrays should do these checks and a bit more, rendering your code even more robust.