# Buggy code
def tile(cls, op):
    df = op.outputs[0]
    tensor = op.inputs[0]

    nsplit_acc = np.cumsum(tensor.nsplits[0])
    out_chunks = []
    for chunk in tensor.chunks:
        begin_index = nsplit_acc[chunk.index[0]] - chunk.shape[0]
        end_index = nsplit_acc[chunk.index[0]]
        chunk_index_value = parse_index(
            pd.RangeIndex(start=begin_index, stop=end_index)
        )

        # Here the `new_chunk` is tricky:
        #
        # We can construct tensor that have identifcal chunks, for example, from `mt.ones(...)`, we know
        # that after tiling the chunk of the same shape (but at different position) in `mt.ones` is indeed
        # the same chunk (has the same key)!
        #
        # Thus, when we construct dataframe from such tensor, we will have dataframe chunks that only differ
        # in `index_value`. However the `index_value` field won't be used to calculate the chunk key of
        # the dataframe chunk, thus `new_chunk` generated the same keys for those indeed different chunks
        # (they have different `index_values`).
        #
        # Here, we construct new chunk with some unique `_extra_params` to make the `new_chunk` work as
        # expected.
        chunk_op = op.copy().reset_key()
        chunk_op.extra_params["begin_index"] = begin_index
        chunk_op.extra_params["end_index"] = end_index
        out_chunk = chunk_op.new_chunk(
            [chunk],
            shape=(chunk.shape[0], df.shape[1]),
            index=(chunk.index[0], 0),
            dtypes=df.dtypes,
            index_value=chunk_index_value,
            columns_value=df.columns,
        )
        out_chunks.append(out_chunk)

    new_op = op.copy()
    return new_op.new_dataframes(
        [tensor],
        df.shape,
        dtypes=df.dtypes,
        index_value=df.index_value,
        columns_value=df.columns,
        chunks=out_chunks,
        nsplits=[tensor.nsplits[0], [df.shape[1]]],
    )


# Traceback (Exception)
In [28]: df = md.DataFrame(np.random.rand(10, 2))

In [29]: df + np.random.rand(10, 2)
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-29-4a212df011a8> in <module>
----> 1 df + np.random.rand(10, 2)

~/Documents/mars_dev/mars/mars/dataframe/utils.py in wrapper(*args, **kwargs)
613     def wrapper(*args, **kwargs):
614         try:
--> 615             return func(*args, **kwargs)
616         except NotImplementedError:
617             return NotImplemented

~/Documents/mars_dev/mars/mars/dataframe/arithmetic/add.py in add(df, other, axis, level, fill_value)
33
34 def add(df, other, axis='columns', level=None, fill_value=None):
---> 35     other = wrap_sequence(other)
36     op = DataFrameAdd(axis=axis, level=level, fill_value=fill_value, lhs=df, rhs=other)
37     return op(df, other)

~/Documents/mars_dev/mars/mars/dataframe/utils.py in wrap_sequence(seq)
606
607     if isinstance(seq, (list, tuple, np.ndarray, TENSOR_TYPE)):
--> 608         seq = Series(seq)
609     return seq
610

~/Documents/mars_dev/mars/mars/dataframe/initializer.py in __init__(self, data, index, dtype, name, copy, chunk_size, gpu, sparse)
46             series = data
47         else:
---> 48             pd_series = pd.Series(data, index=index, dtype=dtype, name=name, copy=copy)
49             series = from_pandas_series(pd_series, chunk_size=chunk_size, gpu=gpu, sparse=sparse)
50         super(Series, self).__init__(series.data)

~/miniconda3/lib/python3.7/site-packages/pandas/core/series.py in __init__(self, data, index, dtype, name, copy, fastpath)
312                     data = data.copy()
313             else:
--> 314                 data = sanitize_array(data, index, dtype, copy, raise_cast_failure=True)
315
316                 data = SingleBlockManager(data, index, fastpath=True)

~/miniconda3/lib/python3.7/site-packages/pandas/core/internals/construction.py in sanitize_array(data, index, dtype, copy, raise_cast_failure)
727     elif subarr.ndim > 1:
728         if isinstance(data, np.ndarray):
--> 729             raise Exception("Data must be 1-dimensional")
730         else:
731             subarr = com.asarray_tuplesafe(data, dtype=dtype)

Exception: Data must be 1-dimensional

# Fixed code
def tile(cls, op):
    df = op.outputs[0]
    tensor = op.inputs[0]

    nsplit_acc = np.cumsum(tensor.nsplits[0])
    out_chunks = []
    for chunk in tensor.chunks:
        begin_index = nsplit_acc[chunk.index[0]] - chunk.shape[0]
        end_index = nsplit_acc[chunk.index[0]]
        chunk_index_value = parse_index(
            pd.RangeIndex(start=begin_index, stop=end_index)
        )

        # Here the `new_chunk` is tricky:
        #
        # We can construct tensor that have identifcal chunks, for example, from `mt.ones(...)`, we know
        # that after tiling the chunk of the same shape (but at different position) in `mt.ones` is indeed
        # the same chunk (has the same key)!
        #
        # Thus, when we construct dataframe from such tensor, we will have dataframe chunks that only differ
        # in `index_value`. However the `index_value` field won't be used to calculate the chunk key of
        # the dataframe chunk, thus `new_chunk` generated the same keys for those indeed different chunks
        # (they have different `index_values`).
        #
        # Here, we construct new chunk with some unique `_extra_params` to make the `new_chunk` work as
        # expected.
        chunk_op = op.copy().reset_key()
        chunk_op.extra_params["begin_index"] = begin_index
        chunk_op.extra_params["end_index"] = end_index
        out_chunk = chunk_op.new_chunk(
            [chunk],
            shape=(chunk.shape[0], df.shape[1]),
            index=(chunk.index[0], 0),
            dtypes=df.dtypes,
            index_value=chunk_index_value,
            columns_value=df.columns_value,
        )
        out_chunks.append(out_chunk)

    new_op = op.copy()
    return new_op.new_dataframes(
        [tensor],
        df.shape,
        dtypes=df.dtypes,
        index_value=df.index_value,
        columns_value=df.columns_value,
        chunks=out_chunks,
        nsplits=[tensor.nsplits[0], [df.shape[1]]],
    )