[numexpr] 01/02: Fix compatibility with numpy 1.12

Antonio Valentino a_valentino-guest at moszumanska.debian.org
Sat Dec 24 21:17:51 UTC 2016


This is an automated email from the git hooks/post-receive script.

a_valentino-guest pushed a commit to branch master
in repository numexpr.

commit f10250d0b2b4b4cf623d5cd9921573dff4014e6c
Author: Antonio Valentino <antonio.valentino at tiscali.it>
Date:   Sat Dec 24 20:57:52 2016 +0000

    Fix compatibility with numpy 1.12
---
 debian/changelog                                   |   8 ++
 debian/patches/0002-numpy-1.12-compatibility.patch | 104 +++++++++++++++++++++
 debian/patches/series                              |   1 +
 3 files changed, 113 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index 8c03c85..4b17827 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,11 @@
+numexpr (2.6.1-3) UNRELEASED; urgency=medium
+
+  * debian/patches
+    - new 0002-numpy-1.12-compatibility.patch to fix compatibility
+      with numpy 1.12 (Closes: #848771)
+
+ -- Antonio Valentino <antonio.valentino at tiscali.it>  Sat, 24 Dec 2016 20:53:46 +0000
+
 numexpr (2.6.1-2) unstable; urgency=high
 
   * debian/patches
diff --git a/debian/patches/0002-numpy-1.12-compatibility.patch b/debian/patches/0002-numpy-1.12-compatibility.patch
new file mode 100644
index 0000000..60252c0
--- /dev/null
+++ b/debian/patches/0002-numpy-1.12-compatibility.patch
@@ -0,0 +1,104 @@
+From: Antonio Valentino <antonio.valentino at tiscali.it>
+Date: Sat, 24 Dec 2016 21:52:23 +0100
+Subject: numpy 1.12 compatibility
+
+---
+ numexpr/expressions.py        | 10 ++++++++++
+ numexpr/tests/test_numexpr.py | 45 +++++++++++++++++++++++++++++++------------
+ 2 files changed, 43 insertions(+), 12 deletions(-)
+
+diff --git a/numexpr/expressions.py b/numexpr/expressions.py
+index 1bb2a80..2c77563 100644
+--- a/numexpr/expressions.py
++++ b/numexpr/expressions.py
+@@ -15,6 +15,8 @@ import sys
+ import threading
+ 
+ import numpy
++from distutils.version import LooseVersion
++_np_version = LooseVersion(numpy.__version__)
+ 
+ # Declare a double type that does not exist in Python space
+ double = numpy.double
+@@ -280,6 +282,14 @@ def rtruediv_op(a, b):
+ 
+ @ophelper
+ def pow_op(a, b):
++    if (_np_version >= '1.12.0b1' and
++        b.astKind in ('int', 'long') and
++        a.astKind in ('int', 'long') and
++        numpy.any(b.value < 0)):
++
++        raise ValueError(
++            'Integers to negative integer powers are not allowed.')
++
+     if allConstantNodes([a, b]):
+         return ConstantNode(a ** b)
+     if isinstance(b, ConstantNode):
+diff --git a/numexpr/tests/test_numexpr.py b/numexpr/tests/test_numexpr.py
+index 7e6e27a..7cc9dca 100644
+--- a/numexpr/tests/test_numexpr.py
++++ b/numexpr/tests/test_numexpr.py
+@@ -566,29 +566,50 @@ def test_expressions():
+         this_locals = locals()
+ 
+         def method():
+-            # We don't want to listen at RuntimeWarnings like
+-            # "overflows" or "divide by zero" in plain eval().
+-            warnings.simplefilter("ignore")
+-            npval = eval(expr, globals(), this_locals)
+-            warnings.simplefilter("always")
+-            npval = eval(expr, globals(), this_locals)
++            try:
++                # We don't want to listen at RuntimeWarnings like
++                # "overflows" or "divide by zero" in plain eval().
++                warnings.simplefilter("ignore")
++                npval = eval(expr, globals(), this_locals)
++                warnings.simplefilter("always")
++                npval = eval(expr, globals(), this_locals)
++            except Exception as ex:
++                # just store the exception in a variable
++                # compatibility with numpy v1.12
++                # see also https://github.com/pydata/numexpr/issues/239
++                np_exception = ex
++                npval = None
++            else:
++                np_exception = None
++
+             try:
+                 neval = evaluate(expr, local_dict=this_locals,
+                                  optimization=optimization)
+-                assert equal(npval, neval, exact), """%r
+-(test_scalar=%r, dtype=%r, optimization=%r, exact=%r,
+- npval=%r (%r - %r)\n neval=%r (%r - %r))""" % (expr, test_scalar, dtype.__name__,
+-                                                optimization, exact,
+-                                                npval, type(npval), shape(npval),
+-                                                neval, type(neval), shape(neval))
+             except AssertionError:
+                 raise
+             except NotImplementedError:
+                 print('%r not implemented for %s (scalar=%d, opt=%s)'
+                       % (expr, dtype.__name__, test_scalar, optimization))
++            except Exception as ne_exception:
++                same_exc_type = issubclass(type(ne_exception),
++                                           type(np_exception))
++                if np_exception is None or not same_exc_type:
++                    print('numexpr error for expression %r' % (expr,))
++                    raise
+             except:
+                 print('numexpr error for expression %r' % (expr,))
+                 raise
++            else:
++                msg = ('expected numexpr error not raised for expression '
++                       '%r' % (expr,))
++                assert np_exception is None, msg
++
++                assert equal(npval, neval, exact), """%r
++(test_scalar=%r, dtype=%r, optimization=%r, exact=%r,
++ npval=%r (%r - %r)\n neval=%r (%r - %r))""" % (expr, test_scalar, dtype.__name__,
++                                                optimization, exact,
++                                                npval, type(npval), shape(npval),
++                                                neval, type(neval), shape(neval))
+ 
+         method.description = ('test_expressions(%s, test_scalar=%r, '
+                               'dtype=%r, optimization=%r, exact=%r)') \
diff --git a/debian/patches/series b/debian/patches/series
index 70f3d60..79ab7d9 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1 +1,2 @@
 0001-fix-test-on-powerpc-and-ppc64el.patch
+0002-numpy-1.12-compatibility.patch

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/numexpr.git



More information about the debian-science-commits mailing list