# Buggy code
def _calc_chunk_params(
    cls, in_chunk, axes, chunk_shape, output, output_type, chunk_op, no_shuffle: bool
):
    params = {"index": in_chunk.index}
    if output_type == OutputType.tensor:
        shape_c = list(in_chunk.shape)
        for ax in axes:
            if not no_shuffle and chunk_shape[ax] > 1:
                shape_c[ax] = np.nan
        params["shape"] = tuple(shape_c)
        params["dtype"] = in_chunk.dtype
        params["order"] = output.order
    elif output_type == OutputType.dataframe:
        shape_c = list(in_chunk.shape)
        if 0 in axes:
            if not no_shuffle and chunk_shape[0] > 1:
                shape_c[0] = np.nan
        params["shape"] = tuple(shape_c)
        params["dtypes"] = output.dtypes
        params["columns_value"] = output.columns_value
        params["index_value"] = _shuffle_index_value(chunk_op, in_chunk.index_value)
    else:
        assert output_type == OutputType.series
        if no_shuffle:
            params["shape"] = in_chunk.shape
        else:
            params["shape"] = (np.nan,)
        params["name"] = in_chunk.name
        params["index_value"] = _shuffle_index_value(chunk_op, in_chunk.index_value)
        params["dtype"] = in_chunk.dtype
    return params


# Traceback (ValueError)
In [1]: import mars.dataframe as md

In [2]: from mars.deploy.local import new_cluster

In [3]: cluster = new_cluster()
WARNING: Logging before InitGoogleLogging() is written to STDERR
I0710 12:01:39.413233 286952896 store.cc:1149] Allowing the Plasma store to use up to 3.43597GB of memory.
I0710 12:01:39.414255 286952896 store.cc:1176] Starting object store with directory /tmp and huge page support disabled

In [4]: import mars.tensor as mt

In [5]: df = md.DataFrame(mt.random.rand(10, 3))

In [6]: df.execute()
Out[6]:
0         1         2
0  0.212577  0.758511  0.148990
1  0.525289  0.382298  0.331657
2  0.821829  0.991404  0.504818
3  0.910740  0.971152  0.915968
4  0.540863  0.289341  0.546004
5  0.869099  0.257637  0.282307
6  0.738262  0.636345  0.717278
7  0.064604  0.481792  0.356584
8  0.598765  0.156633  0.140831
9  0.873232  0.527147  0.247436

In [7]: def f(in_df):
...:     return in_df.sum().to_pandas()
...:

In [8]: import mars.remote as mr

In [9]: mr.spawn(f, args=(df,)).execute()
Unexpected exception occurred in ExecutionActor.execute_graph. graph_key='6ca5f502ce0c9fbccecc434fde3fbe75'
Traceback (most recent call last):
File "/Users/qinxuye/Workspace/mars/mars/utils.py", line 353, in _wrapped
return func(*args, **kwargs)
File "/Users/qinxuye/Workspace/mars/mars/worker/execution.py", line 481, in execute_graph
no_prepare_chunk_keys=io_meta.get('no_prepare_chunk_keys') or set(),
File "/Users/qinxuye/Workspace/mars/mars/worker/execution.py", line 57, in __init__
graph = self.graph = deserialize_graph(graph_serialized)
File "/Users/qinxuye/Workspace/mars/mars/utils.py", line 283, in deserialize_graph
return graph_cls.from_pb(g)
File "mars/graph.pyx", line 426, in mars.graph.DirectedGraph.from_pb
File "mars/serialize/core.pyx", line 683, in mars.serialize.core.Serializable.from_pb
File "mars/serialize/core.pyx", line 667, in mars.serialize.core.Serializable.deserialize
File "mars/serialize/core.pyx", line 810, in mars.serialize.core.Provider.deserialize_model
File "mars/serialize/core.pyx", line 157, in mars.serialize.core.Field.deserialize
File "mars/serialize/pbserializer.pyx", line 874, in mars.serialize.pbserializer.ProtobufSerializeProvider.deserialize_field
File "mars/serialize/pbserializer.pyx", line 839, in mars.serialize.pbserializer.ProtobufSerializeProvider._deserial_reference_value
File "mars/serialize/core.pyx", line 731, in mars.serialize.core.AttributeAsDict.deserialize
File "mars/serialize/pbserializer.pyx", line 972, in mars.serialize.pbserializer.ProtobufSerializeProvider.deserialize_attribute_as_dict
File "mars/serialize/core.pyx", line 157, in mars.serialize.core.Field.deserialize
File "mars/serialize/pbserializer.pyx", line 878, in mars.serialize.pbserializer.ProtobufSerializeProvider.deserialize_field
File "mars/serialize/pbserializer.pyx", line 293, in mars.serialize.pbserializer.ProtobufSerializeProvider._get_list
File "mars/serialize/pbserializer.pyx", line 812, in mars.serialize.pbserializer.ProtobufSerializeProvider._get_value
File "mars/serialize/pbserializer.pyx", line 802, in mars.serialize.pbserializer.ProtobufSerializeProvider._get_untyped_value
File "mars/serialize/pbserializer.pyx", line 223, in mars.serialize.pbserializer.ProtobufSerializeProvider._get_function
File "/Users/qinxuye/Workspace/mars/mars/remote/core.py", line 46, in __setstate__
chunk = ci[0]().new_chunk(None, _key=ci[1], _id=ci[2], kws=[ci[3]])
File "/Users/qinxuye/Workspace/mars/mars/operands.py", line 347, in new_chunk
return self.new_chunks(inputs, kws=kws, **kw)[0]
File "/Users/qinxuye/Workspace/mars/mars/operands.py", line 341, in new_chunks
return self._new_chunks(inputs, kws=kws, **kwargs)
File "/Users/qinxuye/Workspace/mars/mars/dataframe/fetch/core.py", line 39, in _new_chunks
return super()._new_chunks(inputs, kws=kws, **kw)
File "/Users/qinxuye/Workspace/mars/mars/operands.py", line 315, in _new_chunks
chunk = self._create_chunk(j, index, **create_chunk_kw)
File "/Users/qinxuye/Workspace/mars/mars/operands.py", line 283, in _create_chunk
raise ValueError('output_type should be specified')
ValueError: output_type should be specified
Unhandled exception in promise call
Traceback (most recent call last):
File "/Users/qinxuye/Workspace/mars/mars/promise.py", line 372, in _wrapped
return func(*args, **kwargs)
File "/Users/qinxuye/Workspace/mars/mars/utils.py", line 353, in _wrapped
return func(*args, **kwargs)
File "/Users/qinxuye/Workspace/mars/mars/worker/execution.py", line 481, in execute_graph
no_prepare_chunk_keys=io_meta.get('no_prepare_chunk_keys') or set(),
File "/Users/qinxuye/Workspace/mars/mars/worker/execution.py", line 57, in __init__
graph = self.graph = deserialize_graph(graph_serialized)
File "/Users/qinxuye/Workspace/mars/mars/utils.py", line 283, in deserialize_graph
return graph_cls.from_pb(g)
File "mars/graph.pyx", line 426, in mars.graph.DirectedGraph.from_pb
File "mars/serialize/core.pyx", line 683, in mars.serialize.core.Serializable.from_pb
File "mars/serialize/core.pyx", line 667, in mars.serialize.core.Serializable.deserialize
File "mars/serialize/core.pyx", line 810, in mars.serialize.core.Provider.deserialize_model
File "mars/serialize/core.pyx", line 157, in mars.serialize.core.Field.deserialize
File "mars/serialize/pbserializer.pyx", line 874, in mars.serialize.pbserializer.ProtobufSerializeProvider.deserialize_field
File "mars/serialize/pbserializer.pyx", line 839, in mars.serialize.pbserializer.ProtobufSerializeProvider._deserial_reference_value
File "mars/serialize/core.pyx", line 731, in mars.serialize.core.AttributeAsDict.deserialize
File "mars/serialize/pbserializer.pyx", line 972, in mars.serialize.pbserializer.ProtobufSerializeProvider.deserialize_attribute_as_dict
File "mars/serialize/core.pyx", line 157, in mars.serialize.core.Field.deserialize
File "mars/serialize/pbserializer.pyx", line 878, in mars.serialize.pbserializer.ProtobufSerializeProvider.deserialize_field
File "mars/serialize/pbserializer.pyx", line 293, in mars.serialize.pbserializer.ProtobufSerializeProvider._get_list
File "mars/serialize/pbserializer.pyx", line 812, in mars.serialize.pbserializer.ProtobufSerializeProvider._get_value
File "mars/serialize/pbserializer.pyx", line 802, in mars.serialize.pbserializer.ProtobufSerializeProvider._get_untyped_value
File "mars/serialize/pbserializer.pyx", line 223, in mars.serialize.pbserializer.ProtobufSerializeProvider._get_function
File "/Users/qinxuye/Workspace/mars/mars/remote/core.py", line 46, in __setstate__
chunk = ci[0]().new_chunk(None, _key=ci[1], _id=ci[2], kws=[ci[3]])
File "/Users/qinxuye/Workspace/mars/mars/operands.py", line 347, in new_chunk
return self.new_chunks(inputs, kws=kws, **kw)[0]
File "/Users/qinxuye/Workspace/mars/mars/operands.py", line 341, in new_chunks
return self._new_chunks(inputs, kws=kws, **kwargs)
File "/Users/qinxuye/Workspace/mars/mars/dataframe/fetch/core.py", line 39, in _new_chunks
return super()._new_chunks(inputs, kws=kws, **kw)
File "/Users/qinxuye/Workspace/mars/mars/operands.py", line 315, in _new_chunks
chunk = self._create_chunk(j, index, **create_chunk_kw)
File "/Users/qinxuye/Workspace/mars/mars/operands.py", line 283, in _create_chunk
raise ValueError('output_type should be specified')
ValueError: output_type should be specified
Attempt 1: Unexpected error ValueError occurred in executing operand 6ca5f502ce0c9fbccecc434fde3fbe75 in 0.0.0.0:40516
Traceback (most recent call last):
File "/Users/qinxuye/Workspace/mars/mars/promise.py", line 372, in _wrapped
return func(*args, **kwargs)
File "/Users/qinxuye/Workspace/mars/mars/utils.py", line 353, in _wrapped
return func(*args, **kwargs)
File "/Users/qinxuye/Workspace/mars/mars/worker/execution.py", line 481, in execute_graph
no_prepare_chunk_keys=io_meta.get('no_prepare_chunk_keys') or set(),
File "/Users/qinxuye/Workspace/mars/mars/worker/execution.py", line 57, in __init__
graph = self.graph = deserialize_graph(graph_serialized)
File "/Users/qinxuye/Workspace/mars/mars/utils.py", line 283, in deserialize_graph
return graph_cls.from_pb(g)
File "mars/graph.pyx", line 426, in mars.graph.DirectedGraph.from_pb
return cls.deserialize(SerializableGraph.from_pb(pb_obj))
File "mars/serialize/core.pyx", line 683, in mars.serialize.core.Serializable.from_pb
return cls.deserialize(provider, obj)
File "mars/serialize/core.pyx", line 667, in mars.serialize.core.Serializable.deserialize
obj = provider.deserialize_model(cls, obj, callbacks, key_to_instance)
File "mars/serialize/core.pyx", line 810, in mars.serialize.core.Provider.deserialize_model
field.deserialize(self, model_instance, obj, callbacks, key_to_instance)
File "mars/serialize/core.pyx", line 157, in mars.serialize.core.Field.deserialize
return provider.deserialize_field(self, model_instance, obj, callbacks, key_to_instance)
File "mars/serialize/pbserializer.pyx", line 874, in mars.serialize.pbserializer.ProtobufSerializeProvider.deserialize_field
value = [self._deserial_reference_value(
File "mars/serialize/pbserializer.pyx", line 839, in mars.serialize.pbserializer.ProtobufSerializeProvider._deserial_reference_value
return model.deserialize(self, f_obj, callbacks, key_to_instance)
File "mars/serialize/core.pyx", line 731, in mars.serialize.core.AttributeAsDict.deserialize
obj = provider.deserialize_attribute_as_dict(
File "mars/serialize/pbserializer.pyx", line 972, in mars.serialize.pbserializer.ProtobufSerializeProvider.deserialize_attribute_as_dict
it_field.deserialize(self, model_instance, AttrWrapper(d_obj),
File "mars/serialize/core.pyx", line 157, in mars.serialize.core.Field.deserialize
return provider.deserialize_field(self, model_instance, obj, callbacks, key_to_instance)
File "mars/serialize/pbserializer.pyx", line 878, in mars.serialize.pbserializer.ProtobufSerializeProvider.deserialize_field
value = self._get_list(field_obj, field.type, callbacks, field.weak_ref)
File "mars/serialize/pbserializer.pyx", line 293, in mars.serialize.pbserializer.ProtobufSerializeProvider._get_list
val = self._get_value(it_obj, tp.type if tp is not None else tp,
File "mars/serialize/pbserializer.pyx", line 812, in mars.serialize.pbserializer.ProtobufSerializeProvider._get_value
return self._get_untyped_value(obj, callbacks, weak_ref)
File "mars/serialize/pbserializer.pyx", line 802, in mars.serialize.pbserializer.ProtobufSerializeProvider._get_untyped_value
return ref(self._get_function(obj))
File "mars/serialize/pbserializer.pyx", line 223, in mars.serialize.pbserializer.ProtobufSerializeProvider._get_function
return cloudpickle.loads(x) if x is not None and len(x) > 0 else None
File "/Users/qinxuye/Workspace/mars/mars/remote/core.py", line 46, in __setstate__
chunk = ci[0]().new_chunk(None, _key=ci[1], _id=ci[2], kws=[ci[3]])
File "/Users/qinxuye/Workspace/mars/mars/operands.py", line 347, in new_chunk
return self.new_chunks(inputs, kws=kws, **kw)[0]
File "/Users/qinxuye/Workspace/mars/mars/operands.py", line 341, in new_chunks
return self._new_chunks(inputs, kws=kws, **kwargs)
File "/Users/qinxuye/Workspace/mars/mars/dataframe/fetch/core.py", line 39, in _new_chunks
return super()._new_chunks(inputs, kws=kws, **kw)
File "/Users/qinxuye/Workspace/mars/mars/operands.py", line 315, in _new_chunks
chunk = self._create_chunk(j, index, **create_chunk_kw)
File "/Users/qinxuye/Workspace/mars/mars/operands.py", line 283, in _create_chunk
raise ValueError('output_type should be specified')
ValueError: output_type should be specified

# Fixed code
def _calc_chunk_params(
    cls, in_chunk, axes, chunk_shape, output, output_type, chunk_op, no_shuffle: bool
):
    params = {"index": in_chunk.index}
    if output_type == OutputType.tensor:
        shape_c = list(in_chunk.shape)
        for ax in axes:
            if not no_shuffle and chunk_shape[ax] > 1:
                shape_c[ax] = np.nan
        params["shape"] = tuple(shape_c)
        params["dtype"] = in_chunk.dtype
        params["order"] = output.order
    elif output_type == OutputType.dataframe:
        shape_c = list(in_chunk.shape)
        if 0 in axes:
            if not no_shuffle and chunk_shape[0] > 1:
                shape_c[0] = np.nan
        params["shape"] = tuple(shape_c)
        if 1 not in axes:
            params["dtypes"] = in_chunk.dtypes
            params["columns_value"] = in_chunk.columns_value
        else:
            params["dtypes"] = output.dtypes
            params["columns_value"] = output.columns_value
        params["index_value"] = _shuffle_index_value(chunk_op, in_chunk.index_value)
    else:
        assert output_type == OutputType.series
        if no_shuffle:
            params["shape"] = in_chunk.shape
        else:
            params["shape"] = (np.nan,)
        params["name"] = in_chunk.name
        params["index_value"] = _shuffle_index_value(chunk_op, in_chunk.index_value)
        params["dtype"] = in_chunk.dtype
    return params