xref:#614
I'm sure this is possible with #606 so this issue is mostly just to document my attempt to get this working. Out-of-the box (1.22.0+9.gdb758d0f), attempting to pass an arrow Table or RecordBatch results in a TypeError:
TypeError: nodefault__reduce__duetonon-trivial__cinit__
fromdistributedimportClientimportpandasaspdimportpyarrowaspaclient=Client()
df=pd.DataFrame({'A': list('abc'), 'B': [1,2,3]})
tbl=pa.Table.from_pandas(df, preserve_index=False)
defecho(arg):
returnarg>>>client.submit(echo, df).result().equals(df)
True>>>client.submit(echo, tbl).result()
distributed.protocol.pickle-INFO-Failedtoserialize (pyarrow.TableA: stringB: int64metadata--------
{b'pandas': b'{"index_columns": [], "column_indexes": [], "columns": [{"name":'b' "A", "field_name": "A", "pandas_type": "unicode", "numpy_type":'b' "object", "metadata": null}, {"name": "B", "field_name": "B", "'b'pandas_type": "int64", "numpy_type": "int64", "metadata": null}]'b', "pandas_version": "0.23.1"}'},). Exception: nodefault__reduce__duetonon-trivial__cinit__---------------------------------------------------------------------------TypeErrorTraceback (mostrecentcalllast)
C:\Miniconda3\lib\site-packages\distributed\protocol\pickle.pyindumps(x)
37try:
--->38result=pickle.dumps(x, protocol=pickle.HIGHEST_PROTOCOL)
39iflen(result) <1000:
C:\Miniconda3\lib\site-packages\pyarrow\lib.cp36-win_amd64.pydinpyarrow.lib.RecordBatch.__reduce_cython__()
TypeError: nodefault__reduce__duetonon-trivial__cinit__Duringhandlingoftheaboveexception, anotherexceptionoccurred:
TypeErrorTraceback (mostrecentcalllast)
<ipython-input-48-4e8e2ea90e79>in<module>()
---->1client.submit(echo, tbl).result()
C:\Miniconda3\lib\site-packages\distributed\client.pyinsubmit(self, func, *args, **kwargs)
1236resources={skey: resources} ifresourceselseNone,
1237retries=retries,
->1238fifo_timeout=fifo_timeout)
12391240logger.debug("Submit %s(...), %s", funcname(func), key)
C:\Miniconda3\lib\site-packages\distributed\client.pyin_graph_to_futures(self, dsk, keys, restrictions, loose_restrictions, priority, user_priority, resources, retries, fifo_timeout)
20932094self._send_to_scheduler({'op': 'update-graph',
->2095'tasks': valmap(dumps_task, dsk3),
2096'dependencies': dependencies,
2097'keys': list(flatkeys),
C:\Miniconda3\lib\site-packages\cytoolz\dicttoolz.pyxincytoolz.dicttoolz.valmap()
C:\Miniconda3\lib\site-packages\cytoolz\dicttoolz.pyxincytoolz.dicttoolz.valmap()
C:\Miniconda3\lib\site-packages\distributed\worker.pyindumps_task(task)
799elifnotany(map(_maybe_complex, task[1:])):
800return {'function': dumps_function(task[0]),
-->801'args': warn_dumps(task[1:])}
802returnto_serialize(task)
803C:\Miniconda3\lib\site-packages\distributed\worker.pyinwarn_dumps(obj, dumps, limit)
808defwarn_dumps(obj, dumps=pickle.dumps, limit=1e6):
809""" Dump an object to bytes, warn if those bytes are large """-->810b=dumps(obj)
811ifnot_warn_dumps_warned[0] andlen(b) >limit:
812_warn_dumps_warned[0] =TrueC:\Miniconda3\lib\site-packages\distributed\protocol\pickle.pyindumps(x)
49exceptException:
50try:
--->51returncloudpickle.dumps(x, protocol=pickle.HIGHEST_PROTOCOL)
52exceptExceptionase:
53logger.info("Failed to serialize %s. Exception: %s", x, e)
C:\Miniconda3\lib\site-packages\cloudpickle\cloudpickle.pyindumps(obj, protocol)
893try:
894cp=CloudPickler(file, protocol=protocol)
-->895cp.dump(obj)
896returnfile.getvalue()
897finally:
C:\Miniconda3\lib\site-packages\cloudpickle\cloudpickle.pyindump(self, obj)
266self.inject_addons()
267try:
-->268returnPickler.dump(self, obj)
269exceptRuntimeErrorase:
270if'recursion'ine.args[0]:
C:\Miniconda3\lib\pickle.pyindump(self, obj)
407ifself.proto>=4:
408self.framer.start_framing()
-->409self.save(obj)
410self.write(STOP)
411self.framer.end_framing()
C:\Miniconda3\lib\pickle.pyinsave(self, obj, save_persistent_id)
474f=self.dispatch.get(t)
475iffisnotNone:
-->476f(self, obj) # Call unbound method with explicit self477return478C:\Miniconda3\lib\pickle.pyinsave_tuple(self, obj)
734ifn<=3andself.proto>=2:
735forelementinobj:
-->736save(element)
737# Subtle. Same as in the big comment below.738ifid(obj) inmemo:
C:\Miniconda3\lib\pickle.pyinsave(self, obj, save_persistent_id)
494reduce=getattr(obj, "__reduce_ex__", None)
495ifreduceisnotNone:
-->496rv=reduce(self.proto)
497else:
498reduce=getattr(obj, "__reduce__", None)
C:\Miniconda3\lib\site-packages\pyarrow\lib.cp36-win_amd64.pydinpyarrow.lib.RecordBatch.__reduce_cython__()
TypeError: nodefault__reduce__duetonon-trivial__cinit__
xref:#614
I'm sure this is possible with #606 so this issue is mostly just to document my attempt to get this working. Out-of-the box (
1.22.0+9.gdb758d0f), attempting to pass an arrowTableorRecordBatchresults in aTypeError: