I think that this pattern (deactivate and and re-activate warnings) often appears in scikit-learn and could be factored using a with statement. CC @larsmans