sympy
sympy copied to clipboard
dummify argument in lambdify should be smarter
The default option in lambdify
is dummy=True, which is handles names that aren't valid Python identifiers, like functions, or symbols with weird symbols in them.
However, this option breaks introspection for the lambdified function.
>>> x, y = symbols('x, y')
>>> f = lambdify((x, y), x + y**2)
>>> help(f)
Shows
Help on function <lambda> in module numpy:
<lambda> lambda _Dummy_123, _Dummy_124
Created with lambdify. Signature:
func(x, y)
Expression:
x + y**2
Whereas with
>>> f = lambdify((x, y), x + y**2, dummify=False)
>>> help(f)
you get
Help on function <lambda> in module numpy:
<lambda> lambda x, y
Created with lambdify. Signature:
func(x, y)
Expression:
x + y**2
I think the default should be to dummify only if the names are not valid Python identifiers.
It also seems to break numba.jit (although that has other issues too, see https://github.com/numba/numba/issues/2328).
@asmeurer , I would like to work on this issue
@asmeurer , could you please specify what does smarter means here ?
As I said above, it should only apply when it needs to, i.e., when the names aren't valid Python identifiers.
Could you please refer any starting point in utilities/lambdify.py ?
@asmeurer shouldn't it supposed to throw errors with invalid python identifiers, If you want to set dummify
True only for non-python identifiers then we should add a check to see if the identifier is valid or invalid.
This pull request is related https://github.com/sympy/sympy/pull/11457.
This was fixed by https://github.com/sympy/sympy/pull/14713
needs a test added for this issue
I am working on documenting this at https://github.com/sympy/sympy/pull/13485. It's odd that the default is False
instead of None
for lambdify
, even though the default behavior seems to be to only dummify when necessary. For lambdastr
, the default is None
.
Probably, this and this suggest that the work on this issue is complete. Though I am adding a Could Close
label. @asmeurer
Closing this in reference to the above comment. Please let us know if there is a need to re-open this. Thanks for your contributions.
The default for dummify right now is False
, but it should be None
, which would automatically dummify names that require it, but nothing else (True
would still dummify everything).