I think you should use [`sklearn.utils.validation.assert_all_finite`](https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/utils/validation.py#L22) here.