Workflow : Add nightly release of NumPy in linux workflows#13876
Workflow : Add nightly release of NumPy in linux workflows#13876ilayn merged 6 commits intoscipy:masterfrom
Conversation
|
I don't think we need it on the Python3.7-dbg, just the python 3.9. |
| REAL_DTYPES = Union[np.float32, np.float64, np.longdouble] | ||
| COMPLEX_DTYPES = Union[np.complex64, np.complex128, np.clongdouble] | ||
| DTYPES = Union[REAL_DTYPES, COMPLEX_DTYPES] |
There was a problem hiding this comment.
| REAL_DTYPES = Union[np.float32, np.float64, np.longdouble] | |
| COMPLEX_DTYPES = Union[np.complex64, np.complex128, np.clongdouble] | |
| DTYPES = Union[REAL_DTYPES, COMPLEX_DTYPES] | |
| REAL_DTYPES: List[type] = [np.float32, np.float64, np.longdouble] | |
| COMPLEX_DTYPES: List[type] = [np.complex64, np.complex128, np.clongdouble] | |
| DTYPES = REAL_DTYPES + COMPLEX_DTYPES |
There was a problem hiding this comment.
So what exactly is the goal of these constants?
Are they meant to represent type aliases or a sequence of types?
In the former case the original the original code was correct, in the latter I'd suggest using (unannotated) tuples rather than lists (as tuples can easily be used for expressing inhomogeneous sequences).
There was a problem hiding this comment.
It's not a type annotation, it's a list of dtypes used in testing.
for dtype in REAL_DTYPES:
# run test for dtype
There was a problem hiding this comment.
| REAL_DTYPES = Union[np.float32, np.float64, np.longdouble] | |
| COMPLEX_DTYPES = Union[np.complex64, np.complex128, np.clongdouble] | |
| DTYPES = Union[REAL_DTYPES, COMPLEX_DTYPES] | |
| REAL_DTYPES = (np.float32, np.float64, np.longdouble) | |
| COMPLEX_DTYPES = (np.complex64, np.complex128, np.clongdouble) | |
| DTYPES = REAL_DTYPES + COMPLEX_DTYPES |
Right, If so I'd suggest the changes below (non-explicitly annotated tuples rather than lists).
The advantage of using tuples here is that type checkers can link each DTYPES element to a particular np.inexact subclass, which is not possible with lists as they can only be annotated as homogeneous sequences.
from typing import TYPE_CHECKING
import numpy as np
REAL_DTYPES = (np.float32, np.float64, np.longdouble)
COMPLEX_DTYPES = (np.complex64, np.complex128, np.clongdouble)
DTYPES = REAL_DTYPES + COMPLEX_DTYPES
if TYPE_CHECKING:
# Revealed type is 'numpy.floating[numpy.typing._32Bit*]'
reveal_type(REAL_DTYPES[0]())
# Revealed type is 'numpy.complexfloating[numpy.typing._32Bit*, numpy.typing._32Bit*]'
reveal_type(COMPLEX_DTYPES[0]())
# Revealed type is 'numpy.complexfloating[numpy.typing._64Bit*, numpy.typing._64Bit*]'
reveal_type(DTYPES[4]())There was a problem hiding this comment.
From the build :
scipy/linalg/tests/test_basic.py:32: note: Revealed type is 'numpy.floating[numpy.typing._32Bit*]'
scipy/linalg/tests/test_basic.py:35: note: Revealed type is 'numpy.complexfloating[numpy.typing._32Bit*, numpy.typing._32Bit*]'
scipy/linalg/tests/test_basic.py:38: note: Revealed type is 'numpy.complexfloating[numpy.typing._64Bit*, numpy.typing._64Bit*]'
I think I am not putting the condition snippet in the code, am I?
EDIT: commit the majority of it in d720c56
There was a problem hiding this comment.
I think I am not putting the condition snippet in the code, am I?
Correct, this was merely intended as an example.
| if TYPE_CHECKING: | ||
| Numbers = Union[Type[np.double], Type[np.float32], Type[int]] | ||
| DecMapType = Dict[ | ||
| Tuple[ | ||
| partial, Numbers, int | ||
| ], | ||
| int | ||
| ] |
There was a problem hiding this comment.
| if TYPE_CHECKING: | |
| Numbers = Union[Type[np.double], Type[np.float32], Type[int]] | |
| DecMapType = Dict[ | |
| Tuple[ | |
| partial, Numbers, int | |
| ], | |
| int | |
| ] | |
| DecMapType = Dict[Tuple[Callable, type, int], int] |
There was a problem hiding this comment.
Don't forget the subscription.
EDIT: replace Union[Type[np.float32], Type[np.float64]] with Type[np.floating].
| if TYPE_CHECKING: | |
| Numbers = Union[Type[np.double], Type[np.float32], Type[int]] | |
| DecMapType = Dict[ | |
| Tuple[ | |
| partial, Numbers, int | |
| ], | |
| int | |
| ] | |
| DecMapType = Dict[ | |
| # Or just `Type[np.floating]` instead of the union | |
| Tuple[Callable[..., np.ndarray], Type[np.floating], int], | |
| int, | |
| ] |
There was a problem hiding this comment.
I just tested with mypy and Callable with no arguments works exactly as expected.
Union[Type[np.float32], Type[np.float64]] is also wrong because we have tests for np.longdouble as well.
There was a problem hiding this comment.
I just tested with mypy and Callable with no arguments works exactly as expected.
I'ts no suprise that that Callable without arguments works as expected, as it is equivalent to Callable[..., Any].
Union[Type[np.float32], Type[np.float64]]is also wrong because we have tests fornp.longdoubleas well.
In that case Type[np.floating] would definitely be more appropriate.
| assert_array_almost_equal(x, y) | ||
|
|
||
|
|
||
| if TYPE_CHECKING: |
There was a problem hiding this comment.
This line shouldn't be here. It causes DecMapType to not be defined at runtime, which causes the failures in CI:
NameError: name 'DecMapType' is not defined
In general you only want to use if TYPE_CHECKING is something does not work or is expensive at runtime.
|
I don't see why we are touching the test files for the numpy workflow in this PR. But in any case they are not meant for typing in the first place. These are meant to be looped over not for templating. Each dtype is being tested separately. |
Because the changes in the workflows are breaking the type tests ( |
|
This looks like a numpy/mypy issue instead of scipy to be honest. All that code is doing is putting dtype definitions into a list which is pretty straightforward and valid Python code. What is the error that mypy is complaining about? |
Errors (https://github.com/scipy/scipy/runs/2365780037#step:6:24) were : scipy/fft/_pocketfft/tests/test_real_transforms.py:256: error: Invalid index type "Tuple[partial[Any], Type[int], int]" for "Dict[Tuple[partial[Any], Type[floating[Any]], int], int]"; expected type "Tuple[partial[Any], Type[floating[Any]], int]" [index]
22
scipy/linalg/tests/test_basic.py:26: error: Unsupported operand types for + ("List[Type[object]]" and "List[Type[object]]") [operator]
23
Found 2 errors in 2 files (checked 679 source files) |
|
That sounds like mypy going awry. Lists in Python are by definition heterogeneous. But !, of course, typical typing hell is brought in by these https://stackoverflow.com/questions/65361188/python-typing-concatenate-sequences So the easiest is to spell out DTYPES explicitly and avoid the summation so that we don't need all that typing stuff. |
The changes proposed by @BvB93 seems to be working. Should I let it like that or implement your solution @ilayn ? |
|
If it works, it works. so clicking the button. They are simple changes anyways hence we can revisit them if need be. Thanks all! |
|
This is failing: https://github.com/scipy/scipy/runs/2390972247?check_suite_focus=true Note that changes to GitHub Actions files don't actually take effect until they are in master, for security reasons. The way to test this is to make the action run on your own fork, and push changes directly to master on your fork until the action passes. |
|
Sorry, I have been busy the past days 😕
I think revert and then I’ll submit an other PR to fix it ?
…On Wed 21 Apr 2021 at 09:37, Ilhan Polat ***@***.***> wrote:
@V0lantis <https://github.com/V0lantis> @BvB93 <https://github.com/BvB93>
Are we fixing these in the other PR? Or should we revert it?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#13876 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AI7LNNRQFRKGWAVYU252QU3TJZ6CVANCNFSM43CGQPDA>
.
|
* master: (164 commits) DOC: Add Karl Pearson's reference to chi-square test (scipy#13971) BLD: fix build warnings for causal/anticausal pointers in ndimage MAINT: stats: Fix unused imports and a few other issues related to imports. DOC: fix typo MAINT: Remove duplicate calculations in sokalmichener BUG: spatial: fix weight handling of `distance.sokalmichener`. DOC: update Readme (scipy#13910) MAINT: QMCEngine d input validation (scipy#13940) MAINT: forward port 1.6.3 relnotes REL: add PEP 621 (project metadata in pyproject.toml) support EHN: signal: make `get_window` supports `general_cosine` and `general_hamming` window functions. (scipy#13934) ENH/DOC: pydata sphinx theme polishing (scipy#13814) DOC/MAINT: Add copyright notice to qmc.primes_from_2_to (scipy#13927) BUG: DOC: signal: fix need argument config and add missing doc link for `signal.get_window` DOC: fix subsets docstring (scipy#13926) BUG: signal: fix get_window argument handling and add tests. (scipy#13879) ENH: stats: add 'alternative' parameter to ansari (scipy#13650) BUG: Reactivate conda environment in init MAINT: use dict built-in rather than OrderedDict Revert "CI: Add nightly release of NumPy in linux workflows (scipy#13876)" (scipy#13909) ...
Reference issue
Since some of the PRs are relating on very recent NumPy's changes (as for #13833), we need to pull the NumPy Nightly Release when doing our workflows
What does this implement/fix?
This fetch the Nightly Numpy Release rather than the latest release of Numpy, in order to have the latest changes.
Right now, it it just implemented on the Linux's workflow, as I don't know if it is necessary to have it everywhere. If some more experienced reviewer believe we need it in every workflow, I'll change it right away.