-
-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pickling a Sympy lambdified expression causes built-in functions to be replaced with Numpy functions #167
Comments
The reason is that
I'll have to see what can be done with this, but that seem to be the root of the issue. Maybe Note also that if you don't use |
It seems the trigger is in
I'll keep digging. |
So it looks like the "offending" line in
This doesn't play well with |
Oh, interesting... this could be a big part of the issue why the expressions
A workaround for functions resulting from
Although, I'm not a huge fan of adding code that's specific to 3rd-party objects in I'm going to ping @asmeurer on this, just to be sure that what I'm seeing was done with purpose... as opposed to convenience (or otherwise). I'll have a think on how to proceed, especially after any input from @asmeurer. |
The fix definitely should be in |
That's how lambdify works. Take something like import sympy
x = sympy.Symbol('x')
f = lambdify(x, sympy.sin(x), 'numpy') This is (roughly) equivalent to f = eval("lambda x: sin(x)", globals={'sin': numpy.sin}) (the globals dict will also contain tons of other things, but only In other words, Note that the globals dict is not exactly |
We have complete control over the object that is returned. If dill cannot detect this generically we can add some kind of flag to the object. I would rather not rely on the contents of the docstring, as that could change (and we wouldn't consider it to be API breaking). |
@asmeurer: Ok, good to know, thanks. I think |
…167) git-svn-id: svn+ssh://svn.mystic.cacr.caltech.edu/pathos/dill@951 8bfda07e-5b16-0410-ab1d-fd04ec2748df
fixed in cc76dab |
* tag '0.2.6': (71 commits) release dill-0.2.6 fix: use correct pickler for arrays in other objects (see uqfoundation#163) fix: make a copy of result from vars so doesn't pollute globals (see uqfoundation#167) revert scripts to use .py extension (primarily for windows) don't use .py extension for scripts; edit MANIFEST accordingly completely handle namedtuple pickling Add fallback option for badly named namedtuples remove .py extension from scripts (see uqfoundation#189) fix bug so obj class can point to main allow for rare case where module's name attribute has been deleted remove workaround required for oddity in pypy __doc__ descriptor __name__ changes for issue uqfoundation#175, including workaround for pypy __doc__ descriptor check for dictproxy in _getattr added ClassMethodDescriptorType to dill.objects and register it in dill.dill; modified special handling in _getattr for __prepare__ and __weakref__; fix _create_function when obj.__globals__ is None; modified test_detect and test_selected to reflect the above use sys.hexversion not dill.PY3 for __qualname__ condition in namedtuple test updated test_classdef so rename of namedtuple uses __qualname__ convert test_detect and test_diff for pytest prepare test_module, test_moduledict, test_source, test_temp for pytest move dill_bugs to test_selected; prepare test_selected for pytest update test_classdef as pytest compatible Remove pytest dependency and fix test teardown ...
I found some very strange behavior where using dill.dump to store a Sympy lambdified expression causes built-in functions such as min, max, abs, etc. to be replaced with Numpy functions of the same name.
returns:
Naturally this breaks my code and I'm currently using a hackish fix to replace the builtins after pickling. Here is my setup:
Python 3.5.1
Windows 10 64-bit
dill: 0.2.5
sympy: 0.7.6.1
numpy: 1.11.0
The text was updated successfully, but these errors were encountered: