tBuLi / symfit

Symbolic Fitting; fitting as it should be.
http://symfit.readthedocs.org
MIT License
234 stars 17 forks source link

Create a Model from a constant expression returns an error #355

Open patquem opened 1 year ago

patquem commented 1 year ago

Hello, doing Model({y: 0.}) or CallableModel({y: 0.}) (whatever the constant value in the expression) returns: _AttributeError: 'float' object has no attribute 'freesymbols' That is a problem when, for instance, we want to create a model after n-derivations and variables are no longer present in the expression. Could please fix that or tell me if a work around exists. Thanks, Patrick

pckroon commented 1 year ago

Interesting use-case! This is definitely something I'd like to fix, but I'm not sure on what kind of time-line. With a bit of luck I'll manage a PR within a week or so. In the meantime you can try something along the following lines: Model({y: sympy.Expr(0)}). No idea if that works though.

tBuLi commented 1 year ago

Yes that would work. The PR for this should be really simple actually, because sympy already has a method sympify that does exactly this. So we should first check if the value is an Expr, and if it isn't we call sympify on it. We can probably not call sympify on all our input without checking, because I'm not sure what that would do to e.g. Parameters.