Skip to content
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

Update to work with Python 3.8 and sklearn >0.20.0 #13

Closed
john-sandall opened this issue Jul 4, 2020 · 3 comments
Closed

Update to work with Python 3.8 and sklearn >0.20.0 #13

john-sandall opened this issue Jul 4, 2020 · 3 comments

Comments

@john-sandall
Copy link

I came across some issues/warnings when using Python 3.8 and more recent versions of sklearn when debugging solutions to #11

For example, using Python 3.8 with scikit-learn 0.20.0 you get a couple issues:

1. Warning - sklearn 0.20.0 uses an version of joblib/cloudpickle that uses imp instead of importlib

/Users/john/.virtualenvs/sklearn-genetic/lib/python3.8/site-packages/sklearn/externals/joblib/externals/cloudpickle/cloudpickle.py:47: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp

imp has been deprecated since Python 3.4 but I think the warning maybe only shows on Python 3.8? Relating the sklearn, this is well documented in scikit-learn/scikit-learn#12226 and scikit-learn/scikit-learn#12434 and solved I think in 0.20.1 onwards.

2. TypeError: an integer is required (got type bytes)

This is another incompatibility between Python 3.8 and the bundled versions of joblib/cloudpickle in sklearn 0.20.0, similar to this.

Full traceback:

In [6]: import sklearn
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-b7c74cbf5af0> in <module>
----> 1 import sklearn

~/.virtualenvs/sklearn-genetic/lib/python3.8/site-packages/sklearn/__init__.py in <module>
     63     from . import __check_build
     64     from .base import clone
---> 65     from .utils._show_versions import show_versions
     66
     67     __check_build  # avoid flakes unused variable error

~/.virtualenvs/sklearn-genetic/lib/python3.8/site-packages/sklearn/utils/__init__.py in <module>
     11
     12 from .murmurhash import murmurhash3_32
---> 13 from .validation import (as_float_array,
     14                          assert_all_finite,
     15                          check_random_state, column_or_1d, check_array,

~/.virtualenvs/sklearn-genetic/lib/python3.8/site-packages/sklearn/utils/validation.py in <module>
     25 from ..exceptions import NotFittedError
     26 from ..exceptions import DataConversionWarning
---> 27 from ..utils._joblib import Memory
     28 from ..utils._joblib import __version__ as joblib_version
     29

~/.virtualenvs/sklearn-genetic/lib/python3.8/site-packages/sklearn/utils/_joblib.py in <module>
     16         from joblib import logger
     17 else:
---> 18     from ..externals.joblib import __all__   # noqa
     19     from ..externals.joblib import *  # noqa
     20     from ..externals.joblib import __version__  # noqa

~/.virtualenvs/sklearn-genetic/lib/python3.8/site-packages/sklearn/externals/joblib/__init__.py in <module>
    117 from .numpy_pickle import load
    118 from .compressor import register_compressor
--> 119 from .parallel import Parallel
    120 from .parallel import delayed
    121 from .parallel import cpu_count

~/.virtualenvs/sklearn-genetic/lib/python3.8/site-packages/sklearn/externals/joblib/parallel.py in <module>
     30                                  LokyBackend)
     31 from ._compat import _basestring
---> 32 from .externals.cloudpickle import dumps, loads
     33 from .externals import loky
     34

~/.virtualenvs/sklearn-genetic/lib/python3.8/site-packages/sklearn/externals/joblib/externals/cloudpickle/__init__.py in <module>
      1 from __future__ import absolute_import
      2
----> 3 from .cloudpickle import *
      4
      5 __version__ = '0.5.6'

~/.virtualenvs/sklearn-genetic/lib/python3.8/site-packages/sklearn/externals/joblib/externals/cloudpickle/cloudpickle.py in <module>
    149
    150
--> 151 _cell_set_template_code = _make_cell_set_template_code()
    152
    153

~/.virtualenvs/sklearn-genetic/lib/python3.8/site-packages/sklearn/externals/joblib/externals/cloudpickle/cloudpickle.py in _make_cell_set_template_code()
    130         )
    131     else:
--> 132         return types.CodeType(
    133             co.co_argcount,
    134             co.co_kwonlyargcount,

TypeError: an integer is required (got type bytes)
@john-sandall
Copy link
Author

Digging into things, scikit-learn 0.22 is the first version to explicitly work with Python 3.8: https://github.com/scikit-learn/scikit-learn/blob/0.22/setup.py

This is also confirmed here: scikit-learn/scikit-learn#15328 (comment)

I'm submitting a PR which will use environment markers (see PEP 508 and usage example for setup.py as follows to control for requiring sklearn>=0.22 for Python 3.7 only:

install_requires=[
        "scikit-learn>=0.20;python_version<'3.8'",
        "scikit-learn>=0.22;python_version>='3.8'",
        "deap>=1.0.2",
    ],

@john-sandall
Copy link
Author

Another fun issue is that SelectorMixin exists in different places:

PR on its way that fixes all of this.

@manuel-calzolari
Copy link
Owner

Closed with commit c029c0e. I didn't add the scikit-learn>=0.22 requirement for Python >= 3.8 because I think this is a scikit-learn issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants