MNT properly activate the env in the linting CI#17177
MNT properly activate the env in the linting CI#17177NicolasHug merged 3 commits intoscikit-learn:masterfrom
Conversation
|
A quick review @NicolasHug ? The azure linting job is not checking anything. |
sklearn/utils/tests/test_utils.py
Outdated
| (np.float32("nan"), True), | ||
| (np.float64("nan"), True), | ||
| (np.float(float("nan")), True), | ||
| (np.float32(float("nan")), True), |
There was a problem hiding this comment.
The signature of these functions is,
class float64(floating, builtins.float)
it does seem to work with strings, probably because float is called on them internally, but technically that's not correct.
| fi | ||
| displayName: Run linting | ||
| - bash: | | ||
| set -ex |
There was a problem hiding this comment.
Print executed commands and exit on first failure.
NicolasHug
left a comment
There was a problem hiding this comment.
Thanks @rth
I'm happy with the CI update, but I can't say I'm thrilled by the need to update some perfectly working code for mypy to be happy :/
Do we actually need the changes in the code, considering that mypy was working and running fine before?
| # mypy error: Module 'sklearn.cluster' has no attribute '_hierarchical_fast' | ||
| from . import _hierarchical_fast as _hierarchical # type: ignore |
There was a problem hiding this comment.
mypy doesn't like Cython files?
There was a problem hiding this comment.
Yeah, normally one currently has to write stub files for cython extensions since they don't expose annotations (see e.g. scipy/scipy#11936). I'm hoping this could be done automatically in the future though, since Cython should have all relevant information; possibly cython/cython#2552.
Edit: though actually maybe the issues with imports we are seeing are different. Could be worth investigating.
There was a problem hiding this comment.
When mypy runs on the source (before anything is built), my understanding is that there is no way for mypy to find the module. Is this correct?
There was a problem hiding this comment.
Yes, indeed. For most Cython imports errors will be ignored due to the --ignore-missing-import flag, however not when importing whole modules for some reason,
python/mypy#8575 (comment)
There was a problem hiding this comment.
Also I'm getting these errors locally with scikit-learn correctly build. E.g. without this change,
$ mypy --ignore-missing-imports sklearn/cluster/_agglomerative.py
sklearn/cluster/_agglomerative.py:25: error: Module 'sklearn.cluster' has no attribute '_hierarchical_fast'
Found 1 error in 1 file (checked 1 source file)
$ mypy --ignore-missing-imports sklearn
Success: no issues found in 599 source files
I don't really understand why the full run succeeds..
There was a problem hiding this comment.
I don't really understand why the full run succeeds..
Probably unrelated, but lately I've found that git diff upstream/master -u -- "*.py" | flake8 --diff passes on some branches while build_tools/circle/linting.sh (used by the CI) doesn't.
There was a problem hiding this comment.
Probably unrelated, but lately I've found that git diff upstream/master -u -- "*.py" | flake8 --diff passes on some branches while build_tools/circle/linting.sh (used by the CI) doesn't.
Yes, linting the diff has issues #11336 (comment) and I would like to start dealing with it once we are done with the release.
sklearn/utils/tests/test_utils.py
Outdated
| (np.float("nan"), True), | ||
| (np.float32("nan"), True), | ||
| (np.float64("nan"), True), | ||
| (np.float(float("nan")), True), |
There was a problem hiding this comment.
Remplaced with np.float64(np.nan) which should be better, I think?
I know, running mypy on the full repo also worked fine. I had to make changes as I was getting errors with pre-commit (and the raised errors do make sense). |
thomasjpfan
left a comment
There was a problem hiding this comment.
I have always been concerned with how much knowledge one needs to work around these mypy linting errors. (One can see the mypy errors we are ignoring by greping for # mypy error)
This PR is needed to get the linter to work. Thank you @rth !
|
Thanks @rth |
Fixes linting CI job on azure.
Currently it always returns a green status because the env fails to activate and the error is silenly ignored.The error on master is,
Originally fix added in #17053 see discussion there for more details.