Skip to content

[MRG+2]: Copy pilutils functions that are deprecated in scipy #10427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency reasons, can you use the same naming as all the other packages, i.e.: PILLOW_VERSION=some_version.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it in both conda builds.

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