From 2dd8a5f850c0bf97cc3070466040c718df040118 Mon Sep 17 00:00:00 2001 From: mmatera Date: Sun, 18 Sep 2022 11:08:49 -0300 Subject: [PATCH 1/5] removing n_evaluation --- mathics/algorithm/optimizers.py | 8 ++++---- mathics/core/expression.py | 12 +++++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/mathics/algorithm/optimizers.py b/mathics/algorithm/optimizers.py index 8fe6f0e45..a3f30f166 100644 --- a/mathics/algorithm/optimizers.py +++ b/mathics/algorithm/optimizers.py @@ -210,8 +210,8 @@ def find_root_secant(f, x0, x, opts, evaluation) -> (Number, bool): return x0, False if not isinstance(f1, Number): return x0, False - f0 = f0.to_python(n_evaluation=True) - f1 = f1.to_python(n_evaluation=True) + f0 = eval_N(f0, evaluation).to_python() + f1 = eval_N(f1, evaluation).to_python() count = 0 while count < maxit: if f0 == f1: @@ -232,7 +232,7 @@ def find_root_secant(f, x0, x, opts, evaluation) -> (Number, bool): ) if not isinstance(f1, Number): return x0, False - f1 = f1.to_python(n_evaluation=True) + f1 = eval_N(f1, evaluation).to_python() continue inv_deltaf = from_python(1.0 / (f1 - f0)) @@ -248,7 +248,7 @@ def find_root_secant(f, x0, x, opts, evaluation) -> (Number, bool): ) if not isinstance(f2, Number): return x0, False - f2 = f2.to_python(n_evaluation=True) + f2 = eval_N(f2, evaluation).to_python() f1, f0 = f2, f1 x1, x0 = x2, x1 if x1 == x0 or abs(f2) == 0: diff --git a/mathics/core/expression.py b/mathics/core/expression.py index df3f71fc6..f26be7058 100644 --- a/mathics/core/expression.py +++ b/mathics/core/expression.py @@ -1394,7 +1394,17 @@ def to_python(self, *args, **kwargs): return expression_to_callable_and_args(expr_fn, vars, n_evaluation) if n_evaluation is not None: - value = Expression(SymbolN, self).evaluate(n_evaluation) + from mathics.core.evaluators import eval_N + import warnings + + warnings.warn( + ( + "use of expr.to_python(n_evaluation) is deprecated." + "Use instead eval_N(expr, evaluation).to_python()" + ), + DeprecationWarning, + ) + value = eval_N(self, n_evaluation) return value.to_python() if head is SymbolDirectedInfinity and len(self._elements) == 1: From ae889a0b0a9539e6c86dc139e263f084f1a7a431 Mon Sep 17 00:00:00 2001 From: mmatera Date: Mon, 19 Sep 2022 10:16:54 -0300 Subject: [PATCH 2/5] removing assert --- mathics/core/expression.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/mathics/core/expression.py b/mathics/core/expression.py index f26be7058..e1d277015 100644 --- a/mathics/core/expression.py +++ b/mathics/core/expression.py @@ -1378,21 +1378,20 @@ def to_python(self, *args, **kwargs): String -> '"..."' Function -> python function numbers -> Python number - If kwarg n_evaluation is given, apply N first to the expression. """ from mathics.builtin.base import mathics_to_python - n_evaluation = kwargs.get("n_evaluation", None) - assert n_evaluation is None - head = self._head if head is SymbolFunction: - from mathics.core.convert.function import expression_to_callable_and_args - vars, expr_fn = self.elements - return expression_to_callable_and_args(expr_fn, vars, n_evaluation) + evaluation = kwargs.get("evaluation", None) + if evaluation: + vars, expr_fn = self.elements + return expression_to_callable_and_args(expr_fn, vars, evaluation) + # Backward compatibility + n_evaluation = kwargs.get("n_evaluation", None) if n_evaluation is not None: from mathics.core.evaluators import eval_N import warnings From dedf6a78b2a0b13aed39d68d83314ba58bf440c8 Mon Sep 17 00:00:00 2001 From: mmatera Date: Mon, 19 Sep 2022 13:38:16 -0300 Subject: [PATCH 3/5] fixing a typo in scipy_utils/integrators --- mathics/builtin/scipy_utils/integrators.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mathics/builtin/scipy_utils/integrators.py b/mathics/builtin/scipy_utils/integrators.py index dcda3e919..e89906157 100644 --- a/mathics/builtin/scipy_utils/integrators.py +++ b/mathics/builtin/scipy_utils/integrators.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- import sys -from mathics.builtin import check_requires_list -from mathics.core.utils import IS_PYPY +from mathics.builtin.base import check_requires_list +from mathics.core.util import IS_PYPY if IS_PYPY or not check_requires_list(["scipy", "numpy"]): raise ImportError From 3fdad828cb4b40259f1a82fd098503ad2939886d Mon Sep 17 00:00:00 2001 From: mmatera Date: Tue, 20 Sep 2022 02:05:37 -0300 Subject: [PATCH 4/5] commenting changes in to_python, for future revision. --- mathics/core/expression.py | 34 +++++++++++++++++++++------------- mathics/core/symbols.py | 11 ++++++----- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/mathics/core/expression.py b/mathics/core/expression.py index e1d277015..7f6e5401d 100644 --- a/mathics/core/expression.py +++ b/mathics/core/expression.py @@ -1378,6 +1378,8 @@ def to_python(self, *args, **kwargs): String -> '"..."' Function -> python function numbers -> Python number + + If kwarg n_evaluation is given, apply N first to the expression. """ from mathics.builtin.base import mathics_to_python @@ -1385,24 +1387,30 @@ def to_python(self, *args, **kwargs): if head is SymbolFunction: from mathics.core.convert.function import expression_to_callable_and_args - evaluation = kwargs.get("evaluation", None) - if evaluation: + n_evaluation = kwargs.get("n_evaluation", None) + if n_evaluation: vars, expr_fn = self.elements - return expression_to_callable_and_args(expr_fn, vars, evaluation) + return expression_to_callable_and_args(expr_fn, vars, n_evaluation) - # Backward compatibility + # After some discussion, it seems that this parameter + # is not useful anymore. Let's consider to remove it + # in future versions. n_evaluation = kwargs.get("n_evaluation", None) + # assert n_evaluation is None if n_evaluation is not None: from mathics.core.evaluators import eval_N - import warnings - - warnings.warn( - ( - "use of expr.to_python(n_evaluation) is deprecated." - "Use instead eval_N(expr, evaluation).to_python()" - ), - DeprecationWarning, - ) + + # Eventually, we want to remove this parameter. + # + # import warnings + + # warnings.warn( + # ( + # "use of expr.to_python(n_evaluation) is deprecated." + # "Use instead eval_N(expr, evaluation).to_python()" + # ), + # DeprecationWarning, + # ) value = eval_N(self, n_evaluation) return value.to_python() diff --git a/mathics/core/symbols.py b/mathics/core/symbols.py index aa17bb34c..e0c728f91 100644 --- a/mathics/core/symbols.py +++ b/mathics/core/symbols.py @@ -581,14 +581,15 @@ def to_python(self, *args, python_form: bool = False, **kwargs): # This was introduced before `mathics.core.evaluators.eval_N` # provided a simple way to convert an expression into a number. # Now it makes this routine harder to describe. + # Consider remove this in future versions. n_evaluation = kwargs.get("n_evaluation") if n_evaluation is not None: - import warnings + # import warnings - warnings.warn( - "use instead ``eval_N(obj, evaluation).to_python()``", - DeprecationWarning, - ) + # warnings.warn( + # "use instead ``eval_N(obj, evaluation).to_python()``", + # DeprecationWarning, + # ) from mathics.core.evaluators import eval_N From dac7a92859e0474b89335c40af5b983f738069c7 Mon Sep 17 00:00:00 2001 From: mmatera Date: Sat, 31 Dec 2022 13:31:56 -0300 Subject: [PATCH 5/5] isort --- mathics/core/expression.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mathics/core/expression.py b/mathics/core/expression.py index 4bb2db9c1..87c2021f1 100644 --- a/mathics/core/expression.py +++ b/mathics/core/expression.py @@ -1421,7 +1421,6 @@ def to_python(self, *args, **kwargs): # Eventually, we want to remove this parameter. # # import warnings - # warnings.warn( # ( # "use of expr.to_python(n_evaluation) is deprecated."