-
-
Notifications
You must be signed in to change notification settings - Fork 26.2k
MNT define a parse_version function in sklearn.utils.fixes #17670
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
Conversation
@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. |
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): |
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.
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.
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.
OK.
sklearn/_build_utils/__init__.py
Outdated
from .pre_build_helpers import basic_check_build | ||
from .openmp_helpers import check_openmp_support | ||
|
||
from sklearn.utils.fixes import parse_version |
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 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
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 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>
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) |
sklearn/utils/fixes.py
Outdated
@@ -21,6 +21,12 @@ | |||
|
|||
from .deprecation import deprecated | |||
|
|||
try: | |||
import pkg_resources | |||
parse_version = pkg_resources.parse_version |
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.
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.
sklearn/utils/fixes.py:28: error: Incompatible types in assignment (expression has type "Type[LooseVersion]", variable has type "Callable[[str], Tuple[str, ...]]")
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.
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
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.
@rth Thank you for your advice!
I tried to add it at the end of appropriate lines.
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.
Thanks @hs-nazuna ! A few minor comments but otherwise LGTM.
Co-authored-by: Roman Yurchak <rth.yurchak@gmail.com>
Co-authored-by: Roman Yurchak <rth.yurchak@gmail.com>
I removed |
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. |
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.
Merging, thanks @hs-nazuna !
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. |
…arn#17670) Co-authored-by: Loïc Estève <loic.esteve@ymail.com> Co-authored-by: Roman Yurchak <rth.yurchak@gmail.com>
…arn#17670) Co-authored-by: Loïc Estève <loic.esteve@ymail.com> Co-authored-by: Roman Yurchak <rth.yurchak@gmail.com>
…arn#17670) Co-authored-by: Loïc Estève <loic.esteve@ymail.com> Co-authored-by: Roman Yurchak <rth.yurchak@gmail.com>
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: