-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[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
[MRG+2]: Copy pilutils functions that are deprecated in scipy #10427
Conversation
This pull request introduces 1 alert - view on lgtm.com new alerts:
Comment posted by lgtm.com |
bbb3d24
to
3368e30
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this belongs under externals? Otherwise LGTM
edea9cf
to
71b270b
Compare
Thanks @jnothman for the quick reply. I moved it to externals. I also added Pillow to Travis runners 1 & 2 to verify that the tests are passing there as well. Should I keep this or should I kick it out again? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want a directory sklearn/externals/tests. Would it hurt to have a sklearn/externals/pilutil/ directory?
a930721
to
069e8c9
Compare
Ok. I moved it into its own folder and subpackage. Also I added |
sklearn/datasets/lfw.py
Outdated
@@ -31,8 +31,8 @@ | |||
|
|||
from .base import get_data_home, _fetch_remote, RemoteFileMetadata | |||
from ..utils import Bunch | |||
from ..externals.pilutil import _imread, _imresize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How fast is importing pillow/pil on your machine? I would keep the import local if it will slow accessing datasets significantly just because the user happens to have the library installed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On my machine the import from PIL import Image
takes approx. 0.04 seconds. The import from sklearn.externals.pilutil import _imread, _imresize
takes 0.8 seconds though. Should I keep the global import or should I change it back to a local one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise lgtm
build_tools/travis/install.sh
Outdated
@@ -82,6 +82,10 @@ if [[ "$COVERAGE" == "true" ]]; then | |||
pip install coverage codecov | |||
fi | |||
|
|||
if [[ "$PILLOW" == "true" ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you merge master because your install.sh is outdated: https://github.com/scikit-learn/scikit-learn/blob/master/build_tools/travis/install.sh#L40
I would probably add it to the TO_INSTALL
environment variable if possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rebased on the current master and added the environment variable to TO_INSTALL
for "$DISTRIB" == "conda"
. The disadvantage is that I had to separately add it for the "$DISTRIB" == "ubuntu"
case. Should I keep it like this?
069e8c9
to
4e93951
Compare
Would it be a good idea to skip the test for ubuntu and check that an error is raised and use the conda build for the functionality test. @lesteve WDYT?
|
Atm. the tests are just skipped if pillow is not installed and thus no error would be raised. But I definitely can just add the test to one or both conda builds and skip them on the ubuntu one. My original reasoning for adding it to ubuntu was to check it on both python 2 and 3 (both conda builds are python 3, aren't they?). |
I was counting on appveyor for python 2. The only thing about this ubuntu build is that the version of numpy and scipy are older.
|
4e93951
to
276efe6
Compare
Ok. I changed the last commit accordingly. Should I add pillow to appveyor then? |
yes you can. We were testing this case before (with scipy). I would also do it in circle CI. |
276efe6
to
0f08bf0
Compare
As option 3 seems to be the consensus, I've updated the PR:
PS: The Travis build is canceled before running not just here, but for all PRs that were updated before. There seems to be something wrong with it. (On my fork, Travis is running fine...) |
This pull request introduces 1 alert - view on lgtm.com new alerts:
Comment posted by lgtm.com |
I pushed some tweaks, mostly to reduce differences with respect to the original scipy file. I think I am fine with this PR as it is. If someone wants to have another quick look, be my guest. Probably best to leave it for another PR, but there seems to be some occurences of imread/imresize in doc and examples:
|
This pull request introduces 1 alert - view on lgtm.com new alerts:
Comment posted by lgtm.com |
I pulled master to get #10486 which should (hopefully) make Travis happy. |
This pull request introduces 1 alert - view on lgtm.com new alerts:
Comment posted by lgtm.com |
I agree with lgtm.com at first glance! It looks like there is a valid code
path where strdata is unset!
…On 18 January 2018 at 01:59, sklearn-lgtm ***@***.***> wrote:
This pull request introduces 1 alert - view on lgtm.com
<https://lgtm.com/projects/g/scikit-learn/scikit-learn/rev/pr-35a490acdb3ded66c1232633ca8306149794ca3d>
*new alerts:*
- 1 for Potentially uninitialized local variable
------------------------------
*Comment posted by lgtm.com <https://lgtm.com>*
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#10427 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEz63T9oT7R9ke05L_nzwx0j7fpi6seks5tLgq2gaJpZM4RWz7J>
.
|
First of all: Thanks @lesteve for cleaning up after me! Concerning the complaint of lgtm.com: Therefore, this line, taking the And thus this block will never be called with Although, I do agree that the error message, that the list index of Concerning the errors on Travis: |
I would ignore the lgtm warning, because that's in externals, for the same reason that we do not test code in externals. About the error in Travis, looks like the |
I just pushed an alternative solution for not running tests in externals, fingers crossed. |
This pull request introduces 1 alert - view on lgtm.com new alerts:
Comment posted by lgtm.com |
a8d05f9
to
b36abe1
Compare
This pull request introduces 1 alert - view on lgtm.com new alerts:
Comment posted by lgtm.com |
LGTM, merging, thanks a lot @jotasi! |
Sorry I'm out of the loop, but wouldn't it be better to add a dependency to one of the libraries? That will point people more directly towards the right solution. And we only need this in some rare cases. |
What do you mean by adding a dependency to one of the libraries?
|
To be able to read image, we will need at least pillow + numpy and make the conversion ourself. This is what imageio is doing in fact. Resizing is a more complex thing since that we would need to use scikit-image which would required dependencies as well. |
Reference Issues/PRs
Fixes #10147
See also #10149 which is an incomplete and inactive pull request that attempts to fix the same issue.
What does this implement/fix? Explain your changes.
scipy.misc.pilutil
's functions are deprecated since version 1.0.0 and will be removed in 1.2.0. As decided in the discussion of #10147 this PR copies the functionality needed in scikit-learn (imread
andimresize
) and their respective test cases. Following the discussion in #10149 they are put into a utility module insklearn.util.pilutil
. I only included functionality that is already used in scikit-learn, dropping unneeded functions and parameters.Other comments
I'm still unsure about the following points:
Licensing: As described in SciPy's docs I copied their license's text into the files containing the implementation as well as the tests. Is this sufficient? I'm especially unsure about the images used in the tests which cannot simply include the license text.
Testing: The added tests are not run on Travis as none of the runners installs pillow. Also all other tests that use this functionality are not run. The tests run fine on my machine but it would be nice to add testing on Travis as well. I could add installation of pillow to one/all Travis runners to also execute the tests here. Should this be done or is this unnecessary?
Generally, there were good reasons for SciPy to drop these functions as discussed in the corresponding PR so one might think about following their advice and moving to imageio and maybe skimage in the long run.