From 01af15a136bdfe6bbd0c3c155711632a69e55f98 Mon Sep 17 00:00:00 2001 From: "S.Y. Lee" Date: Fri, 2 Aug 2019 07:48:19 +0900 Subject: [PATCH 1/2] Exception changed after numpy 1.17 --- sympy/utilities/lambdify.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sympy/utilities/lambdify.py b/sympy/utilities/lambdify.py index 35ae7f83d0f..bb0f51a6bd7 100644 --- a/sympy/utilities/lambdify.py +++ b/sympy/utilities/lambdify.py @@ -484,10 +484,15 @@ def lambdify(args, expr, modules=None, p But if we try to pass in a SymPy expression, it fails - >>> g(x + 1) + >>> try: + ... g(x + 1) + ... # NumPy release after 1.17 raises TypeError instead of + ... # AttributeError + ... except (AttributeError, TypeError): + ... raise AttributeError() # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... - AttributeError: 'Add' object has no attribute 'sin' + AttributeError: Now, let's look at what happened. The reason this fails is that ``g`` calls ``numpy.sin`` on the input expression, and ``numpy.sin`` does not From 59c2f96043713fa2fdb7cbf4f0335bbb9667fb54 Mon Sep 17 00:00:00 2001 From: "S.Y. Lee" Date: Fri, 2 Aug 2019 10:06:44 +0900 Subject: [PATCH 2/2] Make numpy test version aware --- sympy/external/tests/test_numpy.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sympy/external/tests/test_numpy.py b/sympy/external/tests/test_numpy.py index 6663d1afd76..1b752bcfc1b 100644 --- a/sympy/external/tests/test_numpy.py +++ b/sympy/external/tests/test_numpy.py @@ -4,6 +4,7 @@ # Always write regular SymPy tests for anything, that can be tested in pure # Python (without numpy). Here we test everything, that a user may need when # using SymPy with NumPy +from distutils.version import LooseVersion from sympy.external import import_module @@ -231,8 +232,15 @@ def test_lambdify(): f = lambdify(x, sin(x), "numpy") prec = 1e-15 assert -prec < f(0.2) - sin02 < prec - with raises(AttributeError): - f(x) # if this succeeds, it can't be a numpy function + + # if this succeeds, it can't be a numpy function + + if LooseVersion(numpy.__version__) >= LooseVersion('1.17'): + with raises(TypeError): + f(x) + else: + with raises(AttributeError): + f(x) def test_lambdify_matrix():