> Is there an existing function in one of the libraries you mention
> that has the desired behavior (in the context of that library)? That would
> help.

Yes, and we are currently parsing and evaluating strings to convey the meaning. 

Patsy is currently used by statsmodels to parse strings in the following way:

```
from patsy import ModelDesc, Term, EvalFactor
ModelDesc([Term([EvalFactor("y")])],
          [Term([]),
           Term([EvalFactor("a")]),
           Term([EvalFactor("a"), EvalFactor("b")]),
           Term([EvalFactor("np.log(x)")])
           ])
```
"Compare to what you get from parsing the above formula:"

```
ModelDesc.from_formula("y ~ a + a:b + np.log(x)")
```

In the past when we have been eval'ing strings, we added functionality so users 
could avoid it (`getattr`, et. al.).

Sympy is rather new, but I think they'd appreciate it since they have an entire 
subpackage for distributions: 

https://docs.sympy.org/latest/modules/stats.html

I do envision other usages, but these are the strongest cases I have right now.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/MZFA265UAJR46KDAGFZ7BWMRHG4RX77H/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to