Skip to content
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

Serializable fn._ #16

Open
EntilZha opened this issue May 17, 2016 · 2 comments
Open

Serializable fn._ #16

EntilZha opened this issue May 17, 2016 · 2 comments

Comments

@EntilZha
Copy link

EntilZha commented May 17, 2016

It would be useful for the underscore function to be serializable. The two primary use cases would be pickling for storage, but more commonly pickling to execute a function in parallel.

The following doesn't work using pickle or the more powerful dill package:

import pickle
import dill
from fn import _ as X

pickle.dumps(X + 1)
# ArityError: getattr((_ + 1), '__getstate__') expected 1 arguments, got 0

dill.dumps(X + 1)
# ArityError: getattr((_ + 1), '__getstate__') expected 1 arguments, got 0

f = X + 1
pickle.dumps(f)
# ArityError: getattr((_ + 1), '__getstate__') expected 1 arguments, got 0

dill.dumps(f)
# ArityError: getattr((_ + 1), '__getstate__') expected 1 arguments, got 0

dill.loads(dill.dumps(lambda x: x + 1))(1)
#2

My very specific use case is for https://github.com/EntilZha/PyFunctional where you can do this to run a map in parallel:

from functional import pseq

# This doesn't work
pseq.range(4).map(X + 1)

# This works
pseq.range(4).map(lambda x: x + 1)
@low-ghost
Copy link

Great idea! You're right, would definitely improve pickle/dill cases and especially true of parallel execution

@cgarciae
Copy link

I think this is issue is critical for using fn.py with spark.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants