1717RecipeContainer is the base class for organizing Parameters, and other
1818RecipeContainers. RecipeOrganizer is an extended RecipeContainer that
1919incorporates equation building, constraints and Restraints.
20- equationFromString creates an Equation instance from a string.
20+ get_equation_from_string creates an Equation instance from a string.
2121"""
2222
23- __all__ = ["RecipeContainer" , "RecipeOrganizer" , "equationFromString " ]
23+ __all__ = ["RecipeContainer" , "RecipeOrganizer" , "get_equation_from_string " ]
2424
2525import re
2626from collections import OrderedDict
160160 removal_version ,
161161)
162162
163+ equationFromString_deprecation_msg = build_deprecation_message (
164+ recipeorganizer_base ,
165+ "equationFromString" ,
166+ "get_equation_from_string" ,
167+ removal_version ,
168+ )
169+
163170
164171class RecipeContainer (Observable , Configurable , Validatable ):
165172 """Base class for organizing pieces of a FitRecipe.
@@ -851,7 +858,7 @@ def register_string_function(self, function_str, name, func_params={}):
851858 """
852859
853860 # Build the equation instance.
854- eq = equationFromString (
861+ eq = get_equation_from_string (
855862 function_str , self ._eqfactory , ns = func_params , buildargs = True
856863 )
857864 eq .name = name
@@ -907,7 +914,9 @@ def evaluate_equation(self, equation_str, func_params={}):
907914 If `func_params` uses a name that is already used for a
908915 variable.
909916 """
910- eq = equationFromString (equation_str , self ._eqfactory , func_params )
917+ eq = get_equation_from_string (
918+ equation_str , self ._eqfactory , func_params
919+ )
911920 try :
912921 returned_value = eq ()
913922 finally :
@@ -969,7 +978,9 @@ def constrain_parameter(self, parameter, constraint_eq, params={}):
969978
970979 if isinstance (constraint_eq , str ):
971980 eqstr = constraint_eq
972- eq = equationFromString (constraint_eq , self ._eqfactory , params )
981+ eq = get_equation_from_string (
982+ constraint_eq , self ._eqfactory , params
983+ )
973984 else :
974985 eq = Equation (root = constraint_eq )
975986 eqstr = constraint_eq .name
@@ -1194,7 +1205,7 @@ def add_restraint(
11941205 """
11951206 if isinstance (param_or_eq , str ):
11961207 eqstr = param_or_eq
1197- eq = equationFromString (param_or_eq , self ._eqfactory , params )
1208+ eq = get_equation_from_string (param_or_eq , self ._eqfactory , params )
11981209 else :
11991210 eq = Equation (root = param_or_eq )
12001211 eqstr = param_or_eq .name
@@ -1489,38 +1500,45 @@ def show(self, pattern="", textwidth=78):
14891500# End RecipeOrganizer
14901501
14911502
1492- def equationFromString (
1503+ def get_equation_from_string (
14931504 eqstr , factory , ns = {}, buildargs = False , argclass = Parameter , argkw = {}
14941505):
1495- """Make an equation from a string.
1506+ """Make an Equation object from a string.
14961507
14971508 Attributes
14981509 ----------
1499- eqstr
1510+ eqstr : str
15001511 A string representation of the equation. The equation must
15011512 consist of numpy operators and "known" Parameters. Parameters
15021513 are known if they are in ns, or already defined in the factory.
1503- factory
1514+ factory : EquationFactory
15041515 An EquationFactory instance.
1505- ns
1506- A dictionary of Parameters indexed by name that are used
1516+ ns : dict, optional
1517+ The dictionary of Parameters indexed by name that are used
15071518 in the eqstr but not already defined in the factory
15081519 (default {}).
1509- buildargs
1520+ buildargs : bool, optional
15101521 A flag indicating whether missing Parameters can be created
15111522 by the Factory (default False). If False, then the a ValueError
15121523 will be raised if there are undefined arguments in the eqstr.
1513- argclass
1524+ argclass : Parameter class, optional
15141525 Class to use when creating new Arguments (default
15151526 Parameter). The class constructor must accept the 'name' key
15161527 word.
1517- argkw
1528+ argkw : dict, optional
15181529 Key word dictionary to pass to the argclass constructor
15191530 (default {}).
15201531
1532+ Returns
1533+ -------
1534+ eq : Equation
1535+ An Equation instance representing the equation in eqstr.
15211536
1522- Raises ValueError if ns uses a name that is already defined in the factory.
1523- Raises ValueError if the equation has undefined parameters.
1537+ Raises
1538+ ------
1539+ ValueError
1540+ If buildargs is False and there are undefined parameters in eqstr
1541+ or if ns uses a name that is already defined in the factory.
15241542 """
15251543
15261544 defined = set (factory .builders .keys ())
@@ -1542,6 +1560,27 @@ def equationFromString(
15421560 return eq
15431561
15441562
1563+ @deprecated (equationFromString_deprecation_msg )
1564+ def equationFromString (
1565+ eqstr , factory , ns = {}, buildargs = False , argclass = Parameter , argkw = {}
1566+ ):
1567+ """This function has been deprecated and will be removed in version
1568+ 4.0.0.
1569+
1570+ Please use
1571+ diffpy.srfit.fitbase.recipeorganizer.get_equation_from_string
1572+ instead.
1573+ """
1574+ return get_equation_from_string (
1575+ eqstr ,
1576+ factory ,
1577+ ns = ns ,
1578+ buildargs = buildargs ,
1579+ argclass = argclass ,
1580+ argkw = argkw ,
1581+ )
1582+
1583+
15451584def _has_clear_constraints (msg ):
15461585 return hasattr (msg , "clear_all_constraints" )
15471586
0 commit comments