-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Fix warnings with Python 3.10 #11962
Conversation
with warnings.catch_warnings(): | ||
# distutils.sysconfig module is deprecated in Python 3.10 | ||
warnings.simplefilter('ignore', DeprecationWarning) | ||
_convolve = load_library("_convolve", LIBRARY_PATH) |
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.
This fix does not look like it is going to work when the deprecated feature is removed. Is there no replacement for this?
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.
Numpy has some plan : numpy/numpy#18588
But here we are using a smaller helper function that relies on distutils to get the shared library extension on different platforms. We could replace this with some custom code I guess.
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.
So, instead of merging this, which would completely mask the real problem, should we wait a bit and see? Not like we can test against Python 3.10 in CI right now anyway...
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 don't think they will fix this in a few weeks, and we/they have time until 3.12
Actions seems to support 3.10b4 now so I'm trying to add a job.
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.
Okay, as long as we open follow-up issue about this, I guess I can live with this for now.
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.
Yes, hopefully this can be an "upstream fix required"!
astropy/utils/introspection.py
Outdated
with warnings.catch_warnings(): | ||
# distutils package is deprecated in Python 3.10 | ||
warnings.simplefilter('ignore', DeprecationWarning) | ||
from distutils.version import LooseVersion |
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.
Oh no... How do we replace this?
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.
You should know : #11714 ;)
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.
Yes, it seems time to get back to that one!!
setup.cfg
Outdated
# RuntimeWarning from convolution, lombscargle, modeling | ||
ignore:invalid value encountered in true_divide:RuntimeWarning | ||
# RuntimeWarning from units, lombscargle | ||
ignore:divide by zero encountered in:RuntimeWarning |
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 comfortable with blanket ignore like this. They should be ignored on a case-by-case basis.
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.
Yes, but it's more work, and at least for lombscargle I have no idea how to fix it.
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 still have a bad feeling about this. This will ignore such warnings for the entire repo, not just the affected subpackages.
Just as a remainder, Python 3.10's release schedule:
|
For the record,
where
|
And the 3.10 job passes 🎉 |
Re: #11962 (comment) -- Can we localize the warning ignore to the places you have identified instead? |
setup.cfg
Outdated
ignore:divide by zero encountered in true_divide:RuntimeWarning:astropy.timeseries.periodograms.lombscargle | ||
ignore:divide by zero encountered in true_divide:RuntimeWarning:astropy.units.quantity | ||
ignore:invalid value encountered in true_divide:RuntimeWarning:astropy.convolution.convolve | ||
ignore:invalid value encountered in true_divide:RuntimeWarning:astropy.modeling.functional_models |
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.
Okay, I guess this is a good compromise. 😸 (And need a follow-up issue.)
@@ -58,6 +58,11 @@ jobs: | |||
python: 3.9 | |||
toxenv: py39-test | |||
|
|||
- name: Python 3.10 with minimal dependencies |
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.
Originally when I attempted this, I put this in devdeps job.
I also wonder if "minimal dependencies" is enough to catch everything...
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.
Also would need a follow up issue to test with proper Python 3.10 when it is released for real.
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.
Yes we'll need to update for rc1 and the final release.
I didn't try with all other dependencies because I'm afraid this will fail somewhere. But it's fine for now, I mean the goal here is to test that we are compatible with 3.10, not to test that other dependencies also are.
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.
Long term I think it's worth bundling this with dev dependencies, especially if they provide a nightly build with dev/rc python.
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.
Not bad, actually! Overall, looks good. I'm surprised by the warning on the one quantity test, though...
astropy/units/core.py
Outdated
@@ -473,7 +473,7 @@ def set_enabled_equivalencies(equivalencies): | |||
>>> from astropy import units as u | |||
>>> with u.set_enabled_equivalencies(u.dimensionless_angles()): | |||
... phase = 0.5 * u.cycle | |||
... np.exp(1j*phase) # doctest: +FLOAT_CMP | |||
... np.exp(1j*phase) # doctest: +FLOAT_CMP +IGNORE_WARNINGS |
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.
Hmm, I'd be interested to know what the actual warning was. I cannot find this in #11821. Is there perhaps a log I can look at? (I've yet to install a beta version of python; if that's easy, I'll do that!)
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.
Same problem as all others failures, dividing a complex by a scalar now raises a warning because of the division by 0j
:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> traceback >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
465 list of equivalent pairs, e.g., as returned by
466 `~astropy.units.equivalencies.dimensionless_angles`.
467
468 Examples
469 --------
470 Exponentiation normally requires dimensionless quantities. To avoid
471 problems with complex phases::
472
473 >>> from astropy import units as u
474 >>> with u.set_enabled_equivalencies(u.dimensionless_angles()):
UNEXPECTED EXCEPTION: RuntimeWarning('divide by zero encountered in cdouble_scalars')
Traceback (most recent call last):
File "/home/sconseil/.pyenv/versions/3.10.0b4/lib/python3.10/doctest.py", line 1348, in __run
exec(compile(example.source, filename, "single",
File "<doctest astropy.units.core.set_enabled_equivalencies[1]>", line 3, in <module>
File "/home/sconseil/dev/astropy/astropy/astropy/units/quantity.py", line 504, in __array_ufunc__
arrays.append(converter(input_) if converter else input_)
File "/home/sconseil/dev/astropy/astropy/astropy/units/core.py", line 988, in convert
return func(_condition_arg(v) / scale1) * scale2
RuntimeWarning: divide by zero encountered in cdouble_scalars
/home/sconseil/dev/astropy/astropy/astropy/units/core.py:474: UnexpectedException
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> entering PDB >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PDB post_mortem >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> /home/sconseil/dev/astropy/astropy/astropy/units/core.py(988)convert()
-> return func(_condition_arg(v) / scale1) * scale2
(Pdb) _condition_arg(v)
0.5j
(Pdb) scale1
0.15915494309189535
(Pdb) _condition_arg(v) / scale1
*** RuntimeWarning: divide by zero encountered in cdouble_scalars
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.
Is this python 3.10 specific? This is completely unphysical, so I'd want to raise a bug report...
astropy/utils/introspection.py
Outdated
with warnings.catch_warnings(): | ||
# distutils package is deprecated in Python 3.10 | ||
warnings.simplefilter('ignore', DeprecationWarning) | ||
from distutils.version import LooseVersion |
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.
Yes, it seems time to get back to that one!!
with warnings.catch_warnings(): | ||
# distutils.sysconfig module is deprecated in Python 3.10 | ||
warnings.simplefilter('ignore', DeprecationWarning) | ||
_convolve = load_library("_convolve", LIBRARY_PATH) |
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.
Yes, hopefully this can be an "upstream fix required"!
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.
LGTM though we need to open several follow-up issues.
I won't merge yet in case subpackage maintainers want to review all the warnings in modeling
(@nden , @perrygreenfield), timeseries
(@astrofrog, @bsipocz), units
(@adrn, @mhvk), and convolution
(@larrybradley, @adonath, @keflavich).
@@ -58,6 +58,11 @@ jobs: | |||
python: 3.9 | |||
toxenv: py39-test | |||
|
|||
- name: Python 3.10 with minimal dependencies |
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.
Long term I think it's worth bundling this with dev dependencies, especially if they provide a nightly build with dev/rc python.
To sum up, all warnings are caused by some kind of division of a complex by a scalar:
|
Weird, so it is a numpy problem, but one that only comes up in python 3.10? I just installed python 3.10 via debian experimental, and indeed cannot reproduce that error with just One question: perhaps we should try with numpy-dev here as well? They seem to have made quite a few fixes for python 3.10 (though nothing that looks really relevant...). If this also gives problems with numpy-dev, they really should know about this... |
Yes, it only happens on Python 3.10 and with Numpy complex values, not with Python ones. Maybe we can try with Numpy's nightly. |
Looks like Numpy dev not compatible with Python 3.10? 🤷 |
No, probably they do not build the nightly wheels for 3.10 yet. |
Hmm passed on Python 3.10 and numpy-dev, it seems. But that is with the ignore still in place, right? |
I commented the filters in the previous commit, so yeah it seems to be OK with numpy dev ! |
Or... we just stick Python 3.10 into devdeps job and be done with it? |
Installing Numpy from the git repo makes the job longer, compiling Numpy. It's an option but we can also wait for Numpy to publish nightly wheels for 3.10. |
@saimn , there is conflict now. FYI |
Fix issues with test_logger and io.fits tests.
All green now :) |
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.
All the cron stuff are broken for different and unrelated reasons, so no point trying to run them here. Let's get this in. Thanks!
Owee, I'm MrMeeseeks, Look at me. There seem to be a conflict, please backport manually. Here are approximate instructions:
And apply the correct labels and milestones. Congratulation you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon! Remember to remove If these instruction are inaccurate, feel free to suggest an improvement. |
ops... Do we need to backport? |
Having a 4.3.x compatible with Python 3.10 would be nice (it will out in ~1 month). I will look at the manual backport later. |
Thanks for the fix @saimn! |
Closes #11821, tests run locally, not sure when we will be able to add a job on Actions.
Fix the deprecation warnings and ignore new
RuntimeWarning
raised in convolution, lombscargle, modeling and units. We should probably address those by either fixing the code or catching them in tests but there are many of them (except for units, only 1 IIRC). So probably to address those when we have a 3.10 job.What should be the milestone, probably 4.3 ?
Description
This pull request is to address ...
Fixes #
Checklist for package maintainer(s)
This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.
Extra CI
label.no-changelog-entry-needed
label.astropy-bot
check might be missing; do not let the green checkmark fool you.backport-X.Y.x
label(s) before merge.