-
Notifications
You must be signed in to change notification settings - Fork 76
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
Extend NumPy compatibility to v1.20 #1010
Conversation
Ok, sorry for the delay. I'm starting a review @benjello! |
Thanks to this PR, the tests on Openfisca-survey-manager now pass (but the |
@sandcha : the HTTPError is far beyond my skill. Should I proceed and merge this PR ? |
@benjello It looks like we have something else to fix to be compatible with Numpy 1.18 (or 1.18.1) as I'm getting this error on typing with $ make test
rm -rf build dist
find . -name '*.pyc' -exec rm \{\} \;
python -m compileall -q .
flake8 `git ls-files | grep "\.py$"`
mypy openfisca_core && mypy openfisca_web_api
openfisca_core/indexed_enums/enum_array.py:67: error: Variable "openfisca_core.indexed_enums.enum_array.IndexedEnumArray" is not valid as a type
openfisca_core/indexed_enums/enum_array.py:67: note: See https://mypy.readthedocs.io/en/latest/common_issues.html#variables-vs-type-aliases
openfisca_core/indexed_enums/enum.py:37: error: Variable "openfisca_core.indexed_enums.enum.IndexedEnumArray" is not valid as a type
openfisca_core/indexed_enums/enum.py:37: note: See https://mypy.readthedocs.io/en/latest/common_issues.html#variables-vs-type-aliases
Found 2 errors in 2 files (checked 119 source files)
make: *** [check-types] Error 1 Here is what I did: In order to try it with an older version of Numpy, the 1.20.2 was uninstalled: |
A quick fix (not really elegant fix) for: openfisca_core/indexed_enums/enum_array.py:67: error: Variable "openfisca_core.indexed_enums.enum_array.IndexedEnumArray" is not valid as a type
openfisca_core/indexed_enums/enum_array.py:67: note: See https://mypy.readthedocs.io/en/latest/common_issues.html#variables-vs-type-aliases would be to add the
to use the previous typing (before #990) on |
The same fix should work for the second error message (
|
The fixes mentioned above cause a new kind of error: the first and second fixes resolve the two errors but when we try to solve the last one which is While removing the |
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.
Thank you for this PR! To be more explicit, as described in the comments, I would approve it if make test
was successful for numpy < 1.20 (aka 1.18 and 1.19). You can dismiss this review when it is fixed :)
Let's wait for @maukoquiroga input. If he does not have a fix without lowering type testing quality I will adopt your suggestion. |
Thanks @benjello and @sandcha. Hard one to crack really 😬 so here are my thoughts, let me know what do you think: This pull request will effectively fix any runtime issue but will still fail at type-cheking, hence Assuming those are two different problems, I'd say this pull request is complete and acceptable if we aim exclusively the former, solving the problem for users, and not the latter, which is actually a problem for contributors. Note: I assume users type-checking their own code won't have any problem as long as they are using a compiled version of the core. If that's not the case, I assume we're dealing with a core's contributor. For the latter, I see two different solutions:
I prefer this solution as generally we want loose dependencies for users and tight dependencies for contributors, in order to avoid as much version-lockings for users as version-incompatibilities for contributors. There's a good overview of this issue here.
If we assume contributors will also need to be able to use these incompatible versions of NumPy, and that we can't know that beforehand —which version will they be using, then 1. won't work. In that case, I see no other option than what @sandcha proposes, but that opens some legit questions: a. Should we provide that compatibility as an exception (so basically doing 1. and 2. at the same time)? b. What should we test against in CI? The most plausible scenario (all the latest acceptable versions of dependencies)? Both NumPy versions' scenarios? Something else?
In this case, we'll face other problems: a. A regression, which is easily fixable by assuming the least modern version of NumPy is being used (what we do for Python versions already). b. Telling the CI to always assume the least modern version of everything (we would have to script it). c. Telling contributors to always assume the least modern version of everything (fixable per 1.). I'd say we go for 1. + this pull request. Thoughts? |
@maukoquiroga @sandcha , let's look at the constraint linked to the numpy version. What do you think ? |
@benjello Doing so will solve one issue, but not the one we want to address here which is about a feature of NumPy available only since 1.20.x (hence we won't be able to dismiss @sandcha's review). I do personally think that is OK to let it loose for people installing the library and tighter for people who want to edit it, and who will care about type-checking the code. Otherwise, I'd we more in favour of dropping the use of |
To be precise, by the look of it, seems that:
|
0k I understand better your point @maukoquiroga so we would go with solution 1. |
Well, actually, it does not seem possible to type-check against different versions of NumPy at the same time, so I guess my proposed solution now would be to:
I still think 1. proposed before to be the right way to go, but maybe it goes a bit beyond what's required for this particular case (requirement of @sandcha that type-checking works for 1.18+). |
This is what I propose to do as well, thanks for that investigative work, here's why: as starting from 1.20.x NumPy provides its own type hints —that is basically why we cannot continue to use |
I am ok with your proposal @maukoquiroga. |
5a53201
to
654fb5c
Compare
Thanks @sandcha ! Regarding minor/major, I reproduce part of my comment on #990:
I'm strongly in favour of a minor here, after all we did actually test changes are compatible with NumPy 1.17.0+ (On a side note, I've tested manually these changes against 1.11.0-1.20.0 and only 1.17.0+ passed, but the situation precedes these changes, so we introduced a breaking-change at some point silently). |
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.
Hello all! Thank you all for your great efforts and reactivity to this issue.
I'm now requesting changes as I think that what we should do in this situation, generally, would be to:
- Yank the problematic version (thanks @sandcha!)
- Restore stable by reverting Upgrade numpy to add support for M1 processors #990 with a patch bump as in Revert side-effects of 23.4.0 on parameters overview route #710 and Downgrade Numpy to 1.17 #926 fixing OpenFisca-Core seems to depend on numpy 1.20 #1009
- Reintroduce Upgrade numpy to add support for M1 processors #990 with these changes as a minor/major.
Note: I'm not blocking because of the minor/major, as there is no visible consensus yet.
I'd also strongly advice we document the way we decide how to handle the situation:
- Semantic versioning regarding changes in our requirements
- Dealing with problematic versions
- Wrong versioning breaking the principle of least astonishment
- Critical bugs introduced breaking usability of the library by users
If you think this request for changes can be dismissed, please do not hesitate to do so, clearly specifying the reasons, so we can include them in the documentation proposed.
Rebasing on |
Done by a revert on 08bcaa5c revert: revert of Drop latest NumPy supported version to 1.18.x
Downgrade revision according to majority opinion for numpy dependency update
6b1fecc
to
c7be456
Compare
Thanks again @sandcha ! 🙏 🙏 🙏 I've just done a fixup of commits and profited to correct versioning (minor => 35.4.0) 😃 Otherwise, I'm OK with all changes. As all commits are of my authorship, it would be great to have your last review & LGTM. |
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.
Thank you all for this PR 🙌
Tested with openfisca-france as an example of a large code base and no error was detected by make test
with numpy 1.20, 1.19 and 1.18.1 (CASD revision).
All seems fine. Dismissing according to this comment #1010 (comment)
Fixes #1009
Edit @maukoquiroga on 27/04/2021
Bug fix
typing
module since 1.20.0annotations
will henceforward no longer workTODO