smarie/python-mini-lambda

What is the possibility of having LambdaExpression and/or LambdaFunction able to be pickled?

Opened this issue · 2 comments

pfw commented

I have a use case for mini_lambda but need to be able to pickle the expression, I've had a quick look around and will do more but I thought I'd ask in case it is something you've considered before or had to rule out?

pfw commented

At the moment this is what I get:

In [56]: pow2= x ** 2

In [57]: pickle.dumps(pow2)
---------------------------------------------------------------------------
RecursionError                            Traceback (most recent call last)
<ipython-input-57-a89ed7061366> in <module>
----> 1 pickle.dumps(pow2)

~/thirdfloor/spatialgroup/pd/.direnv/python-3.6.13/lib/python3.6/site-packages/mini_lambda/main.py in __call__(self, *args, **kwargs)
    328                       + ', '.join([arg_name + '=' + get_repr(arg, None) for arg_name, arg in kwargs.items()]) + ')'
    329         return type(self)(fun=___call__, precedence_level=_PRECEDENCE_SUBSCRIPTION_SLICING_CALL_ATTRREF,
--> 330                           str_expr=string_expr, root_var=root_var, repr_on=self.repr_on)
    331 
    332     # Special case for the string representation

RecursionError: maximum recursion depth exceeded

Hi @pfw thanks a lot for opening this issue !

This was not in the scope of mini lambda at first so there are probably no tests for this, I am not surprised that it does not succeed. Would you like to dig a little and propose a pull request ? I'm afraid that I currently have no bandwidth to work on this issue myself, as these days my open source time goes to other libs.
I can still of course provide integration and release of a working PR - although I'll probably have to update the template of this repo to my latest standards (such as in https://github.com/smarie/python-pyfields/ )