[numexpr] 02/02: numpy 1.12 compatibility
Antonio Valentino
a_valentino-guest at moszumanska.debian.org
Wed Jun 28 20:22:33 UTC 2017
This is an automated email from the git hooks/post-receive script.
a_valentino-guest pushed a commit to branch patch-queue/master
in repository numexpr.
commit daf2291904516b2ee5a673190414d9e336a46f99
Author: Antonio Valentino <antonio.valentino at tiscali.it>
Date: Sat Dec 24 21:52:23 2016 +0100
numpy 1.12 compatibility
Gbp-Pq: Name 0002-numpy-1.12-compatibility.patch
---
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..b8261cf 100644
--- a/numexpr/expressions.py
+++ b/numexpr/expressions.py
@@ -15,6 +15,8 @@ import sys
import threading
import numpy
+from pkg_resources import parse_version
+_np_version = parse_version(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 >= parse_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)') \
--
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