Skip to content

Conversation

hs-nazuna
Copy link
Contributor

@hs-nazuna hs-nazuna commented Jun 23, 2020

Reference Issues/PRs

Resolves #7980
Superses and closes #8301

What does this implement/fix? Explain your changes.

This PR defined a parse_version function in sklearn.utils and replaced some ways to compare versions in some files.

Any other comments?

Fortunately, some files mentioned in #8301 are already fixed by other changes:

  • Deleted files:
    • doc/tutorial/statistical_inference/unsupervised_learning_fixture.py
    • sklearn/utils/arpack.py
  • Other files:
    • sklearn/cross_decomposition/pls_.py
    • sklearn/feature_extraction/tests/test_image.py
    • sklearn/linear_model/least_angle.py
    • sklearn/linear_model/omp.py
    • sklearn/linear_model/tests/test_logistic.py
    • sklearn/metrics/tests/test_classification.py
    • sklearn/model_selection/_search.py
    • sklearn/preprocessing/label.py
    • sklearn/preprocessing/tests/test_data.py
    • sklearn/utils/extmath.py
    • sklearn/utils/tests/test_extmath.py

@glemaitre glemaitre changed the title Define a parse_version function in sklearn.utils MNT define a parse_version function in sklearn.utils.fixes Jun 23, 2020
@lesteve
Copy link
Member

lesteve commented Jun 23, 2020

@hs-nazuna thanks for your PR. I edited your PR description to have "Close #8301" so that the previous PR will be closed if we merge this one.

@lesteve
Copy link
Member

lesteve commented Jun 23, 2020

Hmmm I am not too sure why all the CI are red, investigating ...

@@ -89,7 +89,7 @@ def transform(raw_X, Py_ssize_t n_features, dtype,
indptr_a = np.frombuffer(indptr, dtype=indices_np_dtype)

if indptr[-1] > np.iinfo(np.int32).max: # = 2**31 - 1
if sp_version < (0, 14):
Copy link
Member

Choose a reason for hiding this comment

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

The minimum Scipy supported version is 0.19.1 this should be removed ideally in another PR.

Can you revert this change?

I'll open an issue about his.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK.

from .pre_build_helpers import basic_check_build
from .openmp_helpers import check_openmp_support

from sklearn.utils.fixes import parse_version
Copy link
Member

@lesteve lesteve Jun 23, 2020

Choose a reason for hiding this comment

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

I am not too sure, but I suspect you can not import anything from within sklearn here because this file is used to build sklearn ...

As I may completely be wrong, I would advise you to uninstall/reinstall scikit-learn:

pip uninstall scikit-learn -y
pip install --no-build-isolation --editable .

and check whether you can reproduce the problem in the CI

Copy link
Member

Choose a reason for hiding this comment

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

I reverted this file to not import scikit-learn in my last commit. Hopefully this should get the CI to at least run the tests (i.e. it will avoid that all the CI break during the build).

Co-authored-by: Loïc Estève <loic.esteve@ymail.com>
@hs-nazuna
Copy link
Contributor Author

sklearn/utils/fixes.py:28: error: Incompatible types in assignment (expression has type "Type[LooseVersion]", variable has type "Callable[[str], Tuple[str, ...]]")

How can I avoid this error ...?

The following is my new idea.

def parse_version(version_string):
    try:
        import pkg_resources
        return pkg_resources.parse_version(version_string)
    except ImportError:
        return LooseVersion(version_string)

@@ -21,6 +21,12 @@

from .deprecation import deprecated

try:
import pkg_resources
parse_version = pkg_resources.parse_version
Copy link
Member

@lesteve lesteve Jun 24, 2020

Choose a reason for hiding this comment

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

Looks like mypy is complaining about the fact that parse_version does not have the same signature in both cases. Maybe @rth knows how to tell mypy to not check this? Otherwise googling is definitely an option.

Build log

sklearn/utils/fixes.py:28: error: Incompatible types in assignment (expression has type "Type[LooseVersion]", variable has type "Callable[[str], Tuple[str, ...]]")

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, you can just add

# type: ignore

at the end of each line. There is no easy fix to make those signatures match. https://mypy.readthedocs.io/en/stable/common_issues.html#spurious-errors-and-locally-silencing-the-checker

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rth Thank you for your advice!
I tried to add it at the end of appropriate lines.

Copy link
Member

@rth rth left a comment

Choose a reason for hiding this comment

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

Thanks @hs-nazuna ! A few minor comments but otherwise LGTM.

@lesteve
Copy link
Member

lesteve commented Jun 24, 2020

I removed _parse_version which was no longer used (and is private so it is fine to remove it without deprecation cycle).

@lesteve
Copy link
Member

lesteve commented Jun 24, 2020

I removed another back-slash (similar to one of @rth's comment). I think this looks good and should be good to merge once the CI is green.

I also ran the tests with the minimal version of dependencies just to check that nothing was badly broken.

Copy link
Member

@rth rth left a comment

Choose a reason for hiding this comment

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

Merging, thanks @hs-nazuna !

@rth rth merged commit c29092d into scikit-learn:master Jun 24, 2020
@hs-nazuna hs-nazuna deleted the version_comparison branch June 24, 2020 11:39
@lesteve
Copy link
Member

lesteve commented Jun 24, 2020

Thanks a lot @hs-nazuna it feels good to see a 2-3 year old issue getting closed! Thanks @rth as well for proposing the good compromise of using setuptools in the 99% cases where setuptools is installed.

rubywerman pushed a commit to MLH-Fellowship/scikit-learn that referenced this pull request Jun 24, 2020
…arn#17670)

Co-authored-by: Loïc Estève <loic.esteve@ymail.com>
Co-authored-by: Roman Yurchak <rth.yurchak@gmail.com>
glemaitre pushed a commit to glemaitre/scikit-learn that referenced this pull request Aug 3, 2020
…arn#17670)

Co-authored-by: Loïc Estève <loic.esteve@ymail.com>
Co-authored-by: Roman Yurchak <rth.yurchak@gmail.com>
jayzed82 pushed a commit to jayzed82/scikit-learn that referenced this pull request Oct 22, 2020
…arn#17670)

Co-authored-by: Loïc Estève <loic.esteve@ymail.com>
Co-authored-by: Roman Yurchak <rth.yurchak@gmail.com>
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 this pull request may close these issues.

Improve version comparison for non released versions
3 participants