8000 Add deprecated scipy image-related functions in externals._pilutil (#… · scikit-learn/scikit-learn@afe540c · GitHub
[go: up one dir, main page]

Skip to content

Commit afe540c

Browse files
jotasilesteve
jotasi
authored andcommitted
Add deprecated scipy image-related functions in externals._pilutil (#10427)
1 parent 4c99cd4 commit afe540c

File tree

8 files changed

+515
-44
lines changed

8 files changed

+515
-44
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ matrix:
3636
# Python 3.4 build
3737
- env: DISTRIB="conda" PYTHON_VERSION="3.4" INSTALL_MKL="false"
3838
NUMPY_VERSION="1.10.4" SCIPY_VERSION="0.16.1" CYTHON_VERSION="0.25.2"
39-
COVERAGE=true
39+
PILLOW_VERSION="4.0.0" COVERAGE=true
4040
if: type != cron
4141
# This environment tests the newest supported Anaconda release (5.0.0)
4242
# It also runs tests requiring Pandas and PyAMG
4343
- env: DISTRIB="conda" PYTHON_VERSION="3.6.2" INSTALL_MKL="true"
4444
NUMPY_VERSION="1.13.1" SCIPY_VERSION="0.19.1" PANDAS_VERSION="0.20.3"
45-
CYTHON_VERSION="0.26.1" PYAMG_VERSION="3.3.2" COVERAGE=true
46-
CHECK_PYTEST_SOFT_DEPENDENCY="true"
45+
CYTHON_VERSION="0.26.1" PYAMG_VERSION="3.3.2" PILLOW_VERSION="4.3.0"
46+
COVERAGE=true CHECK_PYTEST_SOFT_DEPENDENCY="true"
4747
if: type != cron
4848
# flake8 linting on diff wrt common ancestor with upstream/master
4949
- env: RUN_FLAKE8="true" SKIP_TESTS="true"

build_tools/appveyor/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ cython
1313
pytest
1414
wheel
1515
wheelhouse_uploader
16+
pillow

build_tools/travis/install.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ if [[ "$DISTRIB" == "conda" ]]; then
5555
TO_INSTALL="$TO_INSTALL pyamg=$PYAMG_VERSION"
5656
fi
5757

58+
if [[ -n "$PILLOW_VERSION" ]]; then
59+
TO_INSTALL="$TO_INSTALL pillow=$PILLOW_VERSION"
60+
fi
61+
5862
conda create -n testenv --yes $TO_INSTALL
5963
source activate testenv
6064

sklearn/datasets/base.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -767,16 +767,9 @@ def load_sample_images():
767767
>>> first_img_data.dtype #doctest: +SKIP
768768
dtype('uint8')
769769
"""
770-
# Try to import imread from scipy. We do this lazily here to prevent
771-
# this module from depending on PIL.
772-
try:
773-
try:
774-
from scipy.misc import imread
775-
except ImportError:
776-
from scipy.misc.pilutil import imread
777-
except ImportError:
778-
raise ImportError("The Python Imaging Library (PIL) "
779-
8000 "is required to load data from jpeg files")
770+
# import PIL only when needed
771+
from ..externals._pilutil import imread
772+
780773
module_path = join(dirname(__file__), "images")
781774
with open(join(module_path, 'README.txt')) as f:
782775
descr = f.read()

sklearn/datasets/lfw.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
from .base import get_data_home, _fetch_remote, RemoteFileMetadata
3333
from ..utils import Bunch
3434
from ..externals.joblib import Memory
35-
3635
from ..externals.six import b
3736

3837
logger = logging.getLogger(__name__)
@@ -136,18 +135,8 @@ def check_fetch_lfw(data_home=None, funneled=True, download_if_missing=True):
136135

137136
def _load_imgs(file_paths, slice_, color, resize):
138137
"""Internally used to load images"""
139-
140-
# Try to import imread and imresize from PIL. We do this here to prevent
141-
# the whole sklearn.datasets module from depending on PIL.
142-
try:
143-
try:
144-
from scipy.misc import imread
145-
except ImportError:
146-
from scipy.misc.pilutil import imread
147-
from scipy.misc import imresize
148-
except ImportError:
149-
raise ImportError("The Python Imaging Library (PIL)"
150-
" is required to load data from jpeg files")
138+
# import PIL only when needed
139+
from ..externals._pilutil import imread, imresize
151140

152141
# compute the portion of the images to load to respect the slice_ parameter
153142
# given by the caller

sklearn/datasets/tests/test_base.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from sklearn.datasets.base import Bunch
2222

2323
from sklearn.externals.six import b, u
24+
from sklearn.externals._pilutil import pillow_installed
2425

2526
from sklearn.utils.testing import assert_false
2627
from sklearn.utils.testing import assert_true
@@ -161,15 +162,7 @@ def test_load_sample_image():
161162

162163

163164
def test_load_missing_sample_image_error():
164-
have_PIL = True
165-
try:
166-
try:
167-
from scipy.misc import imread
168-
except ImportError:
169-
from scipy.misc.pilutil import imread # noqa
170-
except ImportError:
171-
have_PIL = False
172-
if have_PIL:
165+
if pillow_installed:
173166
assert_raises(AttributeError, load_sample_image,
174167
'blop.jpg')
175168
else:

sklearn/datasets/tests/test_lfw.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@
1414
import tempfile
1515
import numpy as np
1616
from sklearn.externals import six
17-
try:
18-
try:
19-
from scipy.misc import imsave
20-
except ImportError:
21-
from scipy.misc.pilutil import imsave
22-
except ImportError:
23-
imsave = None
24-
17+
from sklearn.externals._pilutil import pillow_installed, imsave
2518
from sklearn.datasets import fetch_lfw_pairs
2619
from sklearn.datasets import fetch_lfw_people
2720

@@ -48,7 +41,7 @@
4841

4942
def setup_module():
5043
"""Test fixture run once and common to all tests of this module"""
51-
if imsave is None:
44+
if not pillow_installed:
5245
raise SkipTest("PIL not installed.")
5346

5447
if not os.path.exists(LFW_HOME):

0 commit comments

Comments
 (0)
0