Fix _subexpr method in lambdify

This commit is contained in:
Miro Hrončok 2018-08-14 12:50:22 +02:00
parent 8e1b0e24f1
commit a4a28fcb15
2 changed files with 60 additions and 1 deletions

View File

@ -0,0 +1,52 @@
--- sympy-sympy-1.2/sympy/utilities/lambdify.py.orig 2018-08-14 12:45:57.659778760 +0200
+++ sympy-sympy-1.2/sympy/utilities/lambdify.py 2018-08-14 12:46:12.412849733 +0200
@@ -741,8 +741,7 @@
return argstrs, expr
- @staticmethod
- def _subexpr(expr, dummies_dict):
+ def _subexpr(self, expr, dummies_dict):
from sympy.matrices import DeferredVector
from sympy import sympify
@@ -752,13 +751,13 @@
if isinstance(expr, DeferredVector):
pass
elif isinstance(expr, dict):
- k = [sub_expr(sympify(a), dummies_dict) for a in expr.keys()]
- v = [sub_expr(sympify(a), dummies_dict) for a in expr.values()]
+ k = [self._subexpr(sympify(a), dummies_dict) for a in expr.keys()]
+ v = [self._subexpr(sympify(a), dummies_dict) for a in expr.values()]
expr = dict(zip(k, v))
elif isinstance(expr, tuple):
- expr = tuple(sub_expr(sympify(a), dummies_dict) for a in expr)
+ expr = tuple(self._subexpr(sympify(a), dummies_dict) for a in expr)
elif isinstance(expr, list):
- expr = [sub_expr(sympify(a), dummies_dict) for a in expr]
+ expr = [self._subexpr(sympify(a), dummies_dict) for a in expr]
return expr
def _print_funcargwrapping(self, args):
--- sympy-sympy-1.2/sympy/utilities/tests/test_lambdify.py.orig 2018-08-14 12:46:10.396840035 +0200
+++ sympy-sympy-1.2/sympy/utilities/tests/test_lambdify.py 2018-08-14 12:46:12.413849738 +0200
@@ -883,3 +883,18 @@
# Test that inspect.getsource works but don't hard-code implementation
# details
assert 'x**2' in inspect.getsource(f)
+
+def test_issue_14941():
+ x, y = Dummy(), Dummy()
+
+ # test dict
+ f1 = lambdify([x, y], {x: 3, y: 3}, 'sympy')
+ assert f1(2, 3) == {2: 3, 3: 3}
+
+ # test tuple
+ f2 = lambdify([x, y], (y, x), 'sympy')
+ assert f2(2, 3) == (3, 2)
+
+ # test list
+ f3 = lambdify([x, y], [y, x], 'sympy')
+ assert f3(2, 3) == [3, 2]

View File

@ -1,6 +1,6 @@
Name: sympy
Version: 1.2
Release: 1%{?dist}
Release: 2%{?dist}
Summary: A Python library for symbolic mathematics
License: BSD
URL: http://sympy.org/
@ -11,6 +11,9 @@ Patch0: %{name}-float.patch
Patch1: %{name}-test-code-quality.patch
# Fix a couple of documentation typos
Patch2: %{name}-doc.patch
# Fix _subexpr method in lambdify
# https://github.com/sympy/sympy/pull/14945
Patch3: %{name}-subexpr-lambdify.patch
BuildArch: noarch
@ -111,6 +114,7 @@ HTML documentation for sympy.
%patch0
%patch1
%patch2
%patch3
# If running on a 32-bit system, disable a test that requires 64-bit integers.
%global maxpyint %(python3 -c 'import sys;print("%x" % sys.maxsize)')
@ -263,6 +267,9 @@ popd
%{_docdir}/%{name}-doc/html
%changelog
* Tue Aug 14 2018 Miro Hrončok <mhroncok@redhat.com> - 1.2-2
- Fix _subexpr method in lambdify
* Sat Jul 21 2018 Jerry James <loganjerry@gmail.com> - 1.2-1
- Update to 1.2 (bz 1599502)
- Drop upstreamed -python3 patch