# Buggy code
def _calc_chunk_params(cls, in_chunk, axes, output, output_type, chunk_op):
    params = {"index": in_chunk.index}
    if output_type == OutputType.tensor:
        chunk_shape = list(in_chunk.shape)
        for ax in axes:
            chunk_shape[ax] = np.nan
        params["shape"] = tuple(chunk_shape)
        params["dtype"] = in_chunk.dtype
        params["order"] = output.order
    elif output_type == OutputType.dataframe:
        chunk_shape = list(in_chunk.shape)
        if 0 in axes:
            chunk_shape[0] = np.nan
        params["shape"] = tuple(chunk_shape)
        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
        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 (TypeError)
In [14]: from mars.learn.utils import shuffle

In [15]: X, y = shuffle(X, y)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/Workspace/mars/mars/serialize/jsonserializer.pyx in mars.serialize.jsonserializer.JsonSerializeProvider.serialize_field()

~/Workspace/mars/mars/serialize/jsonserializer.pyx in mars.serialize.jsonserializer.JsonSerializeProvider._serialize_value()

~/Workspace/mars/mars/serialize/jsonserializer.pyx in mars.serialize.jsonserializer.JsonSerializeProvider._serialize_typed_value()

TypeError: Expected tuple, got numpy.ndarray

The above exception was the direct cause of the following exception:

TypeError                                 Traceback (most recent call last)
<ipython-input-15-0c15ee335b21> in <module>
----> 1 X, y = shuffle(X, y)

~/Workspace/mars/mars/learn/utils/shuffle.py in shuffle(*arrays, **options)
413     op = LearnShuffle(axes=axes, seeds=seeds,
414                       output_types=get_output_types(*arrays))
--> 415     shuffled_arrays = op(arrays)
416     if len(arrays) == 1:
417         return shuffled_arrays[0]

~/Workspace/mars/mars/learn/utils/shuffle.py in __call__(self, arrays)
92     def __call__(self, arrays):
93         params = self._calc_params([ar.params for ar in arrays])
---> 94         return self.new_tileables(arrays, kws=params)
95
96     def _shuffle_index_value(self, index_value):

~/Workspace/mars/mars/operands.py in new_tileables(self, inputs, kws, **kw)
351         tileables = self._new_tileables(inputs, kws=kws, **kw)
352         if is_eager_mode():
--> 353             ExecutableTuple(tileables).execute(fetch=False)
354         return tileables
355

~/Workspace/mars/mars/core.py in execute(self, session, **kw)
626         if session is None:
627             session = Session.default_or_local()
--> 628         return session.run(self, **kw)
629
630     def fetch(self, session=None, **kw):

~/Workspace/mars/mars/session.py in run(self, *tileables, **kw)
184         tileables = tuple(mt.tensor(t) if not isinstance(t, (Entity, Base)) else t
185                           for t in tileables)
--> 186         result = self._sess.run(*tileables, **kw)
187
188         for t in tileables:

~/Workspace/mars/mars/deploy/local/session.py in run(self, *tileables, **kw)
124
125         # submit graph to local cluster
--> 126         self._api.submit_graph(self._session_id, json.dumps(graph.to_json(), separators=(',', ':')),
127                                graph_key, targets, compose=compose)
128

~/Workspace/mars/mars/graph.pyx in mars.graph.DirectedGraph.to_json()

~/Workspace/mars/mars/serialize/core.pyx in mars.serialize.core.Serializable.to_json()

~/Workspace/mars/mars/serialize/core.pyx in mars.serialize.core.Serializable.serialize()

~/Workspace/mars/mars/serialize/core.pyx in mars.serialize.core.Provider.serialize_model()

~/Workspace/mars/mars/serialize/core.pyx in mars.serialize.core.Field.serialize()

~/Workspace/mars/mars/serialize/core.pyx in mars.serialize.core.Field.serialize()

~/Workspace/mars/mars/serialize/jsonserializer.pyx in mars.serialize.jsonserializer.JsonSerializeProvider.serialize_field()

~/Workspace/mars/mars/serialize/jsonserializer.pyx in mars.serialize.jsonserializer.JsonSerializeProvider._serialize_reference()

~/Workspace/mars/mars/serialize/core.pyx in mars.serialize.core.AttributeAsDict.serialize()

~/Workspace/mars/mars/serialize/core.pyx in mars.serialize.core.Provider.serialize_attribute_as_dict()

~/Workspace/mars/mars/serialize/core.pyx in mars.serialize.core.Provider.serialize_model()

~/Workspace/mars/mars/serialize/core.pyx in mars.serialize.core.Field.serialize()

~/Workspace/mars/mars/serialize/core.pyx in mars.serialize.core.Field.serialize()

~/Workspace/mars/mars/serialize/jsonserializer.pyx in mars.serialize.jsonserializer.JsonSerializeProvider.serialize_field()

~/Workspace/mars/mars/serialize/jsonserializer.pyx in mars.serialize.jsonserializer.JsonSerializeProvider.serialize_field()

~/Workspace/mars/mars/serialize/jsonserializer.pyx in mars.serialize.jsonserializer.JsonSerializeProvider._serialize_value()

~/Workspace/mars/mars/serialize/jsonserializer.pyx in mars.serialize.jsonserializer.JsonSerializeProvider._serialize_typed_value()

TypeError: Fail to serialize field `seeds` for LearnShuffle <key=4901c18065398f9e19eec455538bc65a>, reason: Expected tuple, got numpy.ndarray

# Fixed code
def _calc_chunk_params(
    cls, in_chunk, axes, output, output_type, chunk_op, no_shuffle: bool
):
    params = {"index": in_chunk.index}
    if output_type == OutputType.tensor:
        chunk_shape = list(in_chunk.shape)
        for ax in axes:
            if not no_shuffle:
                chunk_shape[ax] = np.nan
        params["shape"] = tuple(chunk_shape)
        params["dtype"] = in_chunk.dtype
        params["order"] = output.order
    elif output_type == OutputType.dataframe:
        chunk_shape = list(in_chunk.shape)
        if 0 in axes:
            if not no_shuffle:
                chunk_shape[0] = np.nan
        params["shape"] = tuple(chunk_shape)
        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