From 8f301bfa55479eca824b3294d610f9c1240ec19c Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 30 Jul 2019 21:39:38 -0500 Subject: [PATCH] Workaround for getting numpy.linalg.pinv argument default with numpy 1.17 --- uncertainties/unumpy/core.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/uncertainties/unumpy/core.py b/uncertainties/unumpy/core.py index 6896ba8..91d0c5b 100644 --- a/uncertainties/unumpy/core.py +++ b/uncertainties/unumpy/core.py @@ -532,7 +532,13 @@ def pinv_with_derivatives(arr, input_type, derivatives, rcond): yield term1+term2+term3 # Default rcond argument for the generalization of numpy.linalg.pinv: -pinv_default = numpy.linalg.pinv.__defaults__[0] # Python 1, 2.6+: +try: + pinv_default = numpy.linalg.pinv.__defaults__[0] # Python 1, 2.6+: +except TypeError: + # In numpy 1.17+, pinv is wrapped using a decorator which unfortunately + # results in the metadata (argument defaults) being lost. However, we can + # still get at the original function using the __wrapped__ attribute. + pinv_default = numpy.linalg.pinv.__wrapped__.__defaults__[0] pinv_with_uncert = func_with_deriv_to_uncert_func(pinv_with_derivatives) From 293a027c8510c0994b2ad095d444c4318b0fe7a4 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 31 Jul 2019 21:30:59 -0500 Subject: [PATCH] Fix unumpy test to account for new behavior of numpy 1.17 --- uncertainties/unumpy/test_unumpy.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/uncertainties/unumpy/test_unumpy.py b/uncertainties/unumpy/test_unumpy.py index cacb3d9..5923dfd 100644 --- a/uncertainties/unumpy/test_unumpy.py +++ b/uncertainties/unumpy/test_unumpy.py @@ -62,8 +62,11 @@ def test_numpy(): # Equivalent with an array of AffineScalarFunc objects: try: numpy.exp(arr + ufloat(0, 0)) - except AttributeError: - pass # ! This is usual (but could be avoided) + except (AttributeError, TypeError): + # In numpy<1.17, an AttributeError is raised in this situation. This was + # considered a bug however, and in numpy 1.17 it was changed to a + # TypeError (see PR #12700 in numpy repository) + pass else: raise Exception("numpy.exp unexpectedly worked")