-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
maint(test): suppress warnings from the test suite #23745
Conversation
✅ Hi, I am the SymPy bot. I'm here to help you write a release notes entry. Please read the guide on how to write release notes.
Click here to see the pull request description that was parsed.
|
ead1b96
to
6c9db2a
Compare
@@ -139,7 +139,7 @@ def _get_or_create(self, s, name=None, dtype=None, broadcastable=None): | |||
if key in self.cache: | |||
return self.cache[key] | |||
|
|||
value = aet.tensor(name=name, dtype=dtype, broadcastable=broadcastable) | |||
value = aet.tensor(name=name, dtype=dtype, shape=broadcastable) |
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.
@brandonwillard is this change safe for both Theano and Aesara?
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 another warning that I haven't managed to suppress yet:
Traceback (most recent call last):
File "/opt/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/aesara/link/c/lazylinker_c.py", line 129, in <module>
code = open(cfile).read()
ResourceWarning: unclosed file <_io.TextIOWrapper name='/opt/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/aesara/link/c/c_code/lazylinker_c.c' mode='r' encoding='UTF-8'>
The complaint is about not using with
but it's coming from the Aesara code.
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.
@brandonwillard is this change safe for both Theano and Aesara?
No, it won't work for Theano.
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 another warning that I haven't managed to suppress yet:
Traceback (most recent call last): File "/opt/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/aesara/link/c/lazylinker_c.py", line 129, in <module> code = open(cfile).read() ResourceWarning: unclosed file <_io.TextIOWrapper name='/opt/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/aesara/link/c/c_code/lazylinker_c.c' mode='r' encoding='UTF-8'>
The complaint is about not using
with
but it's coming from the Aesara code.
We can create an Aesara issue for that, but let's see if we can reproduce it in isolation first.
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.
No, it won't work for Theano.
Thanks. I made a spinout PR from this one that included that change but I guess I'll need to revert that and give this more thought: https://github.com/sympy/sympy/pull/23754/files#r917456138
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.
let's see if we can reproduce it in isolation first.
The warning is seen with -Werror
as in
$ python -Werror myscript.py
or alternatively
$ PYTHONWARNINGS=error python myscript.py
Either way the line code = open(cfile).read()
should be changed to use with
if that line is in the codebase.
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've opened a PR to clean up those issues: aesara-devs/aesara#1049.
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.
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.
Another one that I often see is this:
>>> import aesara
WARNING (aesara.tensor.blas): Using NumPy C-API based implementation for BLAS functions.
That one is a logger warning rather than a Warning warning so it isn't filtered in the usual way. There is some code here to hide it:
sympy/sympy/printing/tests/test_aesaracode.py
Lines 18 to 21 in d983589
aesaralogger = logging.getLogger('aesara.configdefaults') | |
aesaralogger.setLevel(logging.CRITICAL) | |
aesara = import_module('aesara') | |
aesaralogger.setLevel(logging.WARNING) |
The problem is that the warning is emitted on import so we would need to guard every place that imports aesara in case some other place imports it first:
sympy/sympy/testing/runtests.py
Line 704 in d983589
if import_module('aesara') is None: |
I'm not sure what the best approach is for that warning but emitting a visible message to stderr during import doesn't seem great. Note that the line of code above is just testing to see if aesara is installed but that triggers the warning.
sympy/plotting/tests/test_plot.py
Outdated
# XXX: This should be fixed in experimental_lambdify or by using | ||
# ordinary lambdify so that it doesn't warn. The error results from | ||
# passing an array of values as the integration limit. | ||
# | ||
# UserWarning: The evaluation of the expression is problematic. We are | ||
# trying a failback method that may still work. Please report this as a | ||
# bug. | ||
with ignore_warnings(UserWarning): | ||
p.save(os.path.join(tmpdir, filename)) |
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'm not sure if there is already an issue for this but I seem to remember a PR that attempted to fix 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.
The issue is #19996
assert list(textplot_str(sqrt(x), -1, 1)) == lines | ||
# RuntimeWarning: invalid value encountered in sqrt | ||
with ignore_warnings(RuntimeWarning): | ||
assert list(textplot_str(sqrt(x), -1, 1)) == 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.
Maybe the plotting module should use np.errstate
if it expects to deliberately pass invalid values:
https://numpy.org/doc/stable/reference/generated/numpy.errstate.html
sympy/external/tests/test_numpy.py
Outdated
@@ -138,9 +139,11 @@ def test_Matrix1(): | |||
|
|||
def test_Matrix2(): | |||
m = Matrix([[x, x**2], [5, 2/x]]) | |||
assert (matrix(m.subs(x, 2)) == matrix([[2, 4], [5, 1]])).all() | |||
with ignore_warnings(PendingDeprecationWarning): | |||
assert (matrix(m.subs(x, 2)) == matrix([[2, 4], [5, 1]])).all() |
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.
As far as I can tell all the tests involving np.matrix
are just checking that it can be used with sympy. It doesn't look like sympy actually uses np.matrix
for anything.
sympy/external/tests/test_codegen.py
Outdated
stderr=subprocess.STDOUT) | ||
if retcode != 0: | ||
return False | ||
with open(os.devnull, 'w') as null: |
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 found cases where with
should be used to ensure that files are closed properly. That should probably be reviewed in bulk across the codebase.
# The ufuncify function generates a setup.py that uses distutils which | ||
# is now deprecated: | ||
# | ||
# DeprecationWarning: The distutils package is deprecated and slated | ||
# for removal in Python 3.12. Use setuptools or check PEP 632 for | ||
# potential alternatives |
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.
Places where distutils is used:
$ git grep distutils
bin/test_travis.sh:import distutils.sysconfig
bin/test_travis.sh:with open(os.path.join(distutils.sysconfig.get_python_lib(), 'coverage.pth'), 'w') as pth:
doc/src/modules/utilities/autowrap.rst:system installed f2py command. The Cython backend runs a distutils setup script
release/fabfile.py: distutils_check()
release/fabfile.py:def distutils_check():
setup.py:This uses Distutils (https://python.org/sigs/distutils-sig/) the standard
setup.py:from distutils.command.sdist import sdist
setup.py: from distutils.core import setup, Command
setup.py: user_options = [] # distutils complains if this is not here.
setup.py: def initialize_options(self): # distutils wants this
setup.py: user_options = [] # distutils complains if this is not here.
setup.py: def initialize_options(self): # distutils wants this
setup.py: user_options = [] # distutils complains if this is not here.
setup.py: def initialize_options(self): # distutils wants this
sympy/external/importtools.py: # Simplified from distutils.version.LooseVersion which was deprecated in
sympy/utilities/_compilation/compilation.py: # from distutils/command/build_ext.py:
sympy/utilities/_compilation/util.py: # distutils: language = c++
sympy/utilities/autowrap.py: from distutils.core import setup
sympy/utilities/autowrap.py: from distutils.extension import Extension
sympy/utilities/autowrap.py: The following optional parameters get passed to ``distutils.Extension``
sympy/utilities/autowrap.py: from numpy.distutils.misc_util import Configuration
sympy/utilities/autowrap.py: from numpy.distutils.core import setup
sympy/utilities/tests/test_autowrap.py: from distutils.core import setup
sympy/utilities/tests/test_autowrap.py: from distutils.extension import Extension
sympy/utilities/tests/test_autowrap.py: from distutils.core import setup
sympy/utilities/tests/test_autowrap.py: from distutils.extension import Extension
sympy/utilities/tests/test_autowrap.py: from distutils.core import setup
sympy/utilities/tests/test_autowrap.py: from distutils.extension import Extension
- Travis and fabfile don't matter.
- The main setup.py should be removed and replaced with
pyproject.toml
. - The external module only shows up because of a comment.
- The problematic cases are all in autowrap.
The autowrap module needs to be changed to not use distutils or numpy.distutils which are both deprecated. It isn't immediately clear to me what the appropriate replacements for these are for a nontrivial setup.py that actually needs to compile some C code.
examples/all.py
Outdated
def load_example_module(example): | ||
"""Loads modules based upon the given package name""" | ||
mod = __import__(example) | ||
return mod | ||
from importlib import import_module | ||
|
||
exmod = os.path.split(EXAMPLE_DIR)[1] | ||
modname = exmod + '.' + example | ||
return import_module(modname) |
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'm not sure if this code is precisely equivalent but the previous code was somewhat over engineered for what actually needs to be done here.
# aesaracode imports aesara which imports distutils which warns: | ||
# | ||
# DeprecationWarning: The distutils package is deprecated and | ||
# slated for removal in Python 3.12. Use setuptools or check PEP | ||
# 632 for potential alternatives | ||
if submodule == 'sympy.printing.aesaracode': | ||
warnings = DeprecationWarning | ||
else: | ||
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.
Lots of places where we need to suppress warnings from Aesara. This can be reverted if Aesara stops using distutils.
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 we have an issue for this change, but I can quickly make a PR regardless.
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.
There is aesara-devs/aesara#758
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, I was thinking of just plain distutils
. I've already created a PR for that, though: aesara-devs/aesara#1050.
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.
It's both kinds of distutils :)
The numpy.distutils deprecation is just a bit louder:
$ python -Werror -c 'import aesara'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/oscar/current/sympy/sympy.git/38venv/lib/python3.8/site-packages/aesara/__init__.py", line 126, in <module>
from aesara import scalar, tensor
File "/home/oscar/current/sympy/sympy.git/38venv/lib/python3.8/site-packages/aesara/scalar/__init__.py", line 1, in <module>
from .basic import *
File "/home/oscar/current/sympy/sympy.git/38venv/lib/python3.8/site-packages/aesara/scalar/basic.py", line 25, in <module>
from aesara import printing
File "/home/oscar/current/sympy/sympy.git/38venv/lib/python3.8/site-packages/aesara/printing.py", line 20, in <module>
from aesara.compile import Function, SharedVariable
File "/home/oscar/current/sympy/sympy.git/38venv/lib/python3.8/site-packages/aesara/compile/__init__.py", line 19, in <module>
from aesara.compile.mode import (
File "/home/oscar/current/sympy/sympy.git/38venv/lib/python3.8/site-packages/aesara/compile/mode.py", line 28, in <module>
from aesara.link.c.basic import CLinker, OpWiseCLinker
File "/home/oscar/current/sympy/sympy.git/38venv/lib/python3.8/site-packages/aesara/link/c/basic.py", line 26, in <module>
from aesara.link.c.cmodule import (
File "/home/oscar/current/sympy/sympy.git/38venv/lib/python3.8/site-packages/aesara/link/c/cmodule.py", line 25, in <module>
import numpy.distutils
File "/home/oscar/current/sympy/sympy.git/38venv/lib/python3.8/site-packages/numpy/distutils/__init__.py", line 31, in <module>
warnings.warn("\n\n"
DeprecationWarning:
`numpy.distutils` is deprecated since NumPy 1.23.0, as a result
of the deprecation of `distutils` itself. It will be removed for
Python >= 3.12. For older Python versions it will remain present.
It is recommended to use `setuptools < 60.0` for those Python versions.
For more details, see:
https://numpy.org/devdocs/reference/distutils_status_migration.html
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 right, I added both to that PR.
|
||
# Warning when importing jax (comes indirectly because jax imports | ||
# flatbuffers): | ||
# | ||
# DeprecationWarning: the imp module is deprecated in favour of importlib; see | ||
# the module's documentation for alternative uses | ||
with ignore_warnings(DeprecationWarning): | ||
jax = import_module('jax') |
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.
with ignore_warnings(DeprecationWarning): | ||
# Warnings when importing tensorflow: | ||
# | ||
# DeprecationWarning: The distutils package is deprecated and slated for | ||
# removal in Python 3.12. Use setuptools or check PEP 632 for potential | ||
# alternatives | ||
from sympy.printing.tensorflow import tensorflow_code | ||
tf = tensorflow = import_module("tensorflow") |
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.
Similar to Aesara. When tensorflow stops using distutils these kinds of changes can be reverted.
# XXX: Sampling with scipy under -Werror fails with | ||
# | ||
# RuntimeWarning: invalid value encountered in _cdf_single (vectorized) | ||
# | ||
# It isn't immediately clear if this is a bug in SciPy or SymPy. | ||
|
||
with ignore_warnings(RuntimeWarning): | ||
assert sample(Z) in Z.pspace.domain.set | ||
sym, val = list(Z.pspace.sample().items())[0] |
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 warrants further investigation. When I checked in the debugger it looked as if sympy was passing valid inputs to scipy so I don't know if the warning arises from a bug in the scipy code. Need to distil a reproducer that doesn't involve the layers of sympy code that make this quite convoluted to debug.
# XXX: This should be fixed in lambdify to not use numpy functions from the | ||
# scipy module. | ||
# | ||
# DeprecationWarning: scipy.greater is deprecated and will be removed | ||
# in SciPy 2.0.0, use numpy.greater instead | ||
# DeprecationWarning: scipy.sin is deprecated and will be removed in SciPy | ||
# 2.0.0, use numpy.sin instead | ||
with ignore_warnings(DeprecationWarning): | ||
assert P(X + Y > 0, Y < 0, numsamples=10).is_number |
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 is a significant problem in lambdify
. The scipy module has lots of functions that are really just imported from numpy like scipy.sin
etc. These are all now deprecated. That means that lambdify
should always prefer a function like numpy.sin
over scipy.sin
even if the module is set to "scipy".
I'm not sure how easy it is to fix this in lambdify because it isn't clear to me exactly how these names are picked from one module or the other e.g.:
In [8]: f = lambdify(x, sin(x), 'scipy')
In [9]: print(inspect.getsource(f))
def _lambdifygenerated(x):
return sin(x)
sympy/testing/runtests.py
Outdated
@@ -2030,7 +2057,7 @@ def findout_terminal_width(): | |||
process = subprocess.Popen(['stty', '-a'], | |||
stdout=subprocess.PIPE, | |||
stderr=subprocess.PIPE) | |||
stdout = process.stdout.read() | |||
stdout, stderr = process.communicate() |
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.
Similar to using with open
this is needed to ensure that the subprocess completes rather than becoming a dangling zombie process.
e1924c7
to
577ae22
Compare
577ae22
to
eb05e47
Compare
eb05e47
to
e643011
Compare
References to other Issues or PRs
#23061
Brief description of what is fixed or changed
Other comments
Release Notes
NO ENTRY