Fixed ResourceWarnings from inside scikit-learn. Fixes #3410.

Remaining `ResourceWarning`s are due to a bug in Pillow (a PR is being created at the same time).