Skip to content

Commit

Permalink
Add deprecated scipy image-related functions in externals._pilutil (s…
Browse files Browse the repository at this point in the history
  • Loading branch information
jotasi authored and lesteve committed Jan 18, 2018
1 parent 4c99cd4 commit afe540c
Show file tree
Hide file tree
Showing 8 changed files with 515 additions and 44 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ matrix:
# Python 3.4 build
- env: DISTRIB="conda" PYTHON_VERSION="3.4" INSTALL_MKL="false"
NUMPY_VERSION="1.10.4" SCIPY_VERSION="0.16.1" CYTHON_VERSION="0.25.2"
COVERAGE=true
PILLOW_VERSION="4.0.0" COVERAGE=true
if: type != cron
# This environment tests the newest supported Anaconda release (5.0.0)
# It also runs tests requiring Pandas and PyAMG
- env: DISTRIB="conda" PYTHON_VERSION="3.6.2" INSTALL_MKL="true"
NUMPY_VERSION="1.13.1" SCIPY_VERSION="0.19.1" PANDAS_VERSION="0.20.3"
CYTHON_VERSION="0.26.1" PYAMG_VERSION="3.3.2" COVERAGE=true
CHECK_PYTEST_SOFT_DEPENDENCY="true"
CYTHON_VERSION="0.26.1" PYAMG_VERSION="3.3.2" PILLOW_VERSION="4.3.0"
COVERAGE=true CHECK_PYTEST_SOFT_DEPENDENCY="true"
if: type != cron
# flake8 linting on diff wrt common ancestor with upstream/master
- env: RUN_FLAKE8="true" SKIP_TESTS="true"
Expand Down
1 change: 1 addition & 0 deletions build_tools/appveyor/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ cython
pytest
wheel
wheelhouse_uploader
pillow
4 changes: 4 additions & 0 deletions build_tools/travis/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ if [[ "$DISTRIB" == "conda" ]]; then
TO_INSTALL="$TO_INSTALL pyamg=$PYAMG_VERSION"
fi

if [[ -n "$PILLOW_VERSION" ]]; then
TO_INSTALL="$TO_INSTALL pillow=$PILLOW_VERSION"
fi

conda create -n testenv --yes $TO_INSTALL
source activate testenv

Expand Down
13 changes: 3 additions & 10 deletions sklearn/datasets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,16 +767,9 @@ def load_sample_images():
>>> first_img_data.dtype #doctest: +SKIP
dtype('uint8')
"""
# Try to import imread from scipy. We do this lazily here to prevent
# this module from depending on PIL.
try:
try:
from scipy.misc import imread
except ImportError:
from scipy.misc.pilutil import imread
except ImportError:
raise ImportError("The Python Imaging Library (PIL) "
"is required to load data from jpeg files")
# import PIL only when needed
from ..externals._pilutil import imread

module_path = join(dirname(__file__), "images")
with open(join(module_path, 'README.txt')) as f:
descr = f.read()
Expand Down
15 changes: 2 additions & 13 deletions sklearn/datasets/lfw.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from .base import get_data_home, _fetch_remote, RemoteFileMetadata
from ..utils import Bunch
from ..externals.joblib import Memory

from ..externals.six import b

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

def _load_imgs(file_paths, slice_, color, resize):
"""Internally used to load images"""

# Try to import imread and imresize from PIL. We do this here to prevent
# the whole sklearn.datasets module from depending on PIL.
try:
try:
from scipy.misc import imread
except ImportError:
from scipy.misc.pilutil import imread
from scipy.misc import imresize
except ImportError:
raise ImportError("The Python Imaging Library (PIL)"
" is required to load data from jpeg files")
# import PIL only when needed
from ..externals._pilutil import imread, imresize

# compute the portion of the images to load to respect the slice_ parameter
# given by the caller
Expand Down
11 changes: 2 additions & 9 deletions sklearn/datasets/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from sklearn.datasets.base import Bunch

from sklearn.externals.six import b, u
from sklearn.externals._pilutil import pillow_installed

from sklearn.utils.testing import assert_false
from sklearn.utils.testing import assert_true
Expand Down Expand Up @@ -161,15 +162,7 @@ def test_load_sample_image():


def test_load_missing_sample_image_error():
have_PIL = True
try:
try:
from scipy.misc import imread
except ImportError:
from scipy.misc.pilutil import imread # noqa
except ImportError:
have_PIL = False
if have_PIL:
if pillow_installed:
assert_raises(AttributeError, load_sample_image,
'blop.jpg')
else:
Expand Down
11 changes: 2 additions & 9 deletions sklearn/datasets/tests/test_lfw.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,7 @@
import tempfile
import numpy as np
from sklearn.externals import six
try:
try:
from scipy.misc import imsave
except ImportError:
from scipy.misc.pilutil import imsave
except ImportError:
imsave = None

from sklearn.externals._pilutil import pillow_installed, imsave
from sklearn.datasets import fetch_lfw_pairs
from sklearn.datasets import fetch_lfw_people

Expand All @@ -48,7 +41,7 @@

def setup_module():
"""Test fixture run once and common to all tests of this module"""
if imsave is None:
if not pillow_installed:
raise SkipTest("PIL not installed.")

if not os.path.exists(LFW_HOME):
Expand Down
Loading

0 comments on commit afe540c

Please sign in to comment.