diff --git a/kafe2/fit/_base/model.py b/kafe2/fit/_base/model.py index e9d13e85..665ea2ea 100644 --- a/kafe2/fit/_base/model.py +++ b/kafe2/fit/_base/model.py @@ -215,12 +215,7 @@ def parcount(self): @property def x_name(self): """The name of the independent variable. ``None`` for 0 independent variables.""" - # TODO: don't use case differentiation to maintain compatibility with current fit objects - if self._independent_argcount == 0: - return None _pars = list(self.signature.parameters.keys()) - if self._independent_argcount == 1: - return _pars[0] return _pars[0 : self._independent_argcount] @property @@ -262,12 +257,8 @@ def defaults(self, new_defaults): def defaults_dict(self): """The default values for model function parameters as a dict""" _defaults_dict = OrderedDict() - _x_name = self.x_name + _x_name = self.x_name # list of strings - # _x_name can be a list for >1 independent variables. - # Always convert to list for simpler logic. - if type(_x_name) is str: - _x_name = [_x_name] for _par in self.signature.parameters.values(): # skip independent variable parameter if _x_name is not None and _par.name in _x_name: diff --git a/kafe2/test/fit/test_model_functions.py b/kafe2/test/fit/test_model_functions.py index 006cd793..cb28b444 100644 --- a/kafe2/test/fit/test_model_functions.py +++ b/kafe2/test/fit/test_model_functions.py @@ -26,7 +26,7 @@ def model(x, a, b, c): parameter_names=["a", "b", "c"], argcount=4, parcount=3, - x_name="x", + x_name=["x"], defaults=[1.0, 1.0, 1.0], latex_name=r"{\tt model}", parameter_latex_names=["{a}", "{b}", "{c}"], @@ -48,7 +48,7 @@ def other_model(tau, A_0=3.0, tau_0=1.0): parameter_names=["A_0", "tau_0"], argcount=3, parcount=2, - x_name="tau", + x_name=["tau"], defaults=[3.0, 1.0], latex_name=r"{\tt other\_model}", parameter_latex_names=["{A_0}", r"{\tau_0}"], @@ -118,14 +118,16 @@ class TestSymPyIndexed(TestSymPy): def setUp(self): super().setUp() - self._ref_properties_1["parameter_names"].insert(0, self._ref_properties_1["x_name"]) + self._ref_properties_1["parameter_names"] = \ + self._ref_properties_1["x_name"] + self._ref_properties_1["parameter_names"] self._ref_properties_1["parcount"] += 1 - self._ref_properties_1["x_name"] = None + self._ref_properties_1["x_name"] = [] self._ref_properties_1["defaults"].insert(0, 1.0) self._ref_properties_1["parameter_latex_names"].insert(0, r"{x}") - self._ref_properties_2["parameter_names"].insert(0, self._ref_properties_2["x_name"]) + self._ref_properties_2["parameter_names"] = \ + self._ref_properties_2["x_name"] + self._ref_properties_2["parameter_names"] self._ref_properties_2["parcount"] += 1 - self._ref_properties_2["x_name"] = None + self._ref_properties_2["x_name"] = [] self._ref_properties_2["defaults"].insert(0, 1.0) self._ref_properties_2["parameter_latex_names"].insert(0, r"{\tau}")