I have an app that want to serialize only classes/functions which are: no Python primitive data type no Numpy data type no pandas data type.
So, is it possible to filter object to be saved in dill ? (filter by loop on the type)
Thanks,
I have an app that want to serialize only classes/functions which are: no Python primitive data type no Numpy data type no pandas data type.
So, is it possible to filter object to be saved in dill ? (filter by loop on the type)
Thanks,
While this is not a complete solution (i.e. you'd probably want to include more of the modules with pandas
data types, numpy
data types… and also you might want to be more selective for the built-in types by filtering by type
instead of module)… I think it sort of gets you what you want.
>>> import dill
>>> import numpy
>>> import pandas
>>>
>>> target = numpy.array([1,2,3])
>>> dill.dumps(target) if not dill.source.getmodule(type(target)) in [numpy, pandas.core.series, dill.source.getmodule(int)] else None
>>>
>>> target = [1,2,3]
>>> dill.dumps(target) if not dill.source.getmodule(type(target)) in [numpy, pandas.core.series, dill.source.getmodule(int)] else None
>>>
>>> target = lambda x:x
>>> dill.dumps(target) if not dill.source.getmodule(type(target)) in [numpy, pandas.core.series, dill.source.getmodule(int)] else None
>>>
>>> class Foo(object):
... pass
...
>>> target = Foo()
>>> dill.dumps(target) if not dill.source.getmodule(type(target)) in [numpy, pandas.core.series, dill.source.getmodule(int)] else None
'\x80\x02cdill.dill\n_create_type\nq\x00(cdill.dill\n_load_type\nq\x01U\x08TypeTypeq\x02\x85q\x03Rq\x04U\x03Fooq\x05h\x01U\nObjectTypeq\x06\x85q\x07Rq\x08\x85q\t}q\n(U\r__slotnames__q\x0b]q\x0cU\n__module__q\rU\x08__main__q\x0eU\x07__doc__q\x0fNutq\x10Rq\x11)\x81q\x12}q\x13b.'
>>>
However, if you are asking if dill
has such a filtering method, then the answer is no.