# Buggy code
def tile_with_columns(cls, op):
    in_df = op.inputs[0]
    out_df = op.outputs[0]
    col_names = op.col_names
    if not isinstance(col_names, list):
        column_index = calc_columns_index(col_names, in_df)
        out_chunks = []
        dtype = in_df.dtypes[col_names]
        for i in range(in_df.chunk_shape[0]):
            c = in_df.cix[(i, column_index)]
            op = DataFrameIndex(col_names=col_names)
            out_chunks.append(
                op.new_chunk(
                    [c],
                    shape=(c.shape[0],),
                    index=(i,),
                    dtype=dtype,
                    index_value=c.index_value,
                    name=col_names,
                )
            )
        new_op = op.copy()
        return new_op.new_seriess(
            op.inputs,
            shape=out_df.shape,
            dtype=out_df.dtype,
            index_value=out_df.index_value,
            name=out_df.name,
            nsplits=(in_df.nsplits[0],),
            chunks=out_chunks,
        )
    else:
        # combine columns into one chunk and keep the columns order at the same time.
        # When chunk columns are ['c1', 'c2', 'c3'], ['c4', 'c5'],
        # selected columns are ['c2', 'c3', 'c4', 'c2'], `column_splits` will be
        # [(['c2', 'c3'], 0), ('c4', 1), ('c2', 0)].
        selected_index = [calc_columns_index(col, in_df) for col in col_names]
        condition = np.where(np.diff(selected_index))[0] + 1
        column_splits = np.split(col_names, condition)
        column_indexes = np.split(selected_index, condition)

        out_chunks = [[] for _ in range(in_df.chunk_shape[0])]
        column_nsplits = []
        for i, (columns, column_idx) in enumerate(zip(column_splits, column_indexes)):
            dtypes = in_df.dtypes[columns]
            column_nsplits.append(len(columns))
            for j in range(in_df.chunk_shape[0]):
                c = in_df.cix[(j, column_idx[0])]
                index_op = DataFrameIndex(
                    col_names=list(columns), object_type=ObjectType.dataframe
                )
                out_chunk = index_op.new_chunk(
                    [c],
                    shape=(c.shape[0], len(columns)),
                    index=(j, i),
                    dtypes=dtypes,
                    index_value=c.index_value,
                    columns_value=parse_index(pd.Index(columns), store_data=True),
                )
                out_chunks[j].append(out_chunk)
        out_chunks = [item for l in out_chunks for item in l]
        new_op = op.copy()
        nsplits = (in_df.nsplits[0], tuple(column_nsplits))
        return new_op.new_dataframes(
            op.inputs,
            shape=out_df.shape,
            dtypes=out_df.dtypes,
            index_value=out_df.index_value,
            columns_value=out_df.columns,
            chunks=out_chunks,
            nsplits=nsplits,
        )


# 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_with_columns(cls, op):
    in_df = op.inputs[0]
    out_df = op.outputs[0]
    col_names = op.col_names
    if not isinstance(col_names, list):
        column_index = calc_columns_index(col_names, in_df)
        out_chunks = []
        dtype = in_df.dtypes[col_names]
        for i in range(in_df.chunk_shape[0]):
            c = in_df.cix[(i, column_index)]
            op = DataFrameIndex(col_names=col_names)
            out_chunks.append(
                op.new_chunk(
                    [c],
                    shape=(c.shape[0],),
                    index=(i,),
                    dtype=dtype,
                    index_value=c.index_value,
                    name=col_names,
                )
            )
        new_op = op.copy()
        return new_op.new_seriess(
            op.inputs,
            shape=out_df.shape,
            dtype=out_df.dtype,
            index_value=out_df.index_value,
            name=out_df.name,
            nsplits=(in_df.nsplits[0],),
            chunks=out_chunks,
        )
    else:
        # combine columns into one chunk and keep the columns order at the same time.
        # When chunk columns are ['c1', 'c2', 'c3'], ['c4', 'c5'],
        # selected columns are ['c2', 'c3', 'c4', 'c2'], `column_splits` will be
        # [(['c2', 'c3'], 0), ('c4', 1), ('c2', 0)].
        selected_index = [calc_columns_index(col, in_df) for col in col_names]
        condition = np.where(np.diff(selected_index))[0] + 1
        column_splits = np.split(col_names, condition)
        column_indexes = np.split(selected_index, condition)

        out_chunks = [[] for _ in range(in_df.chunk_shape[0])]
        column_nsplits = []
        for i, (columns, column_idx) in enumerate(zip(column_splits, column_indexes)):
            dtypes = in_df.dtypes[columns]
            column_nsplits.append(len(columns))
            for j in range(in_df.chunk_shape[0]):
                c = in_df.cix[(j, column_idx[0])]
                index_op = DataFrameIndex(
                    col_names=list(columns), object_type=ObjectType.dataframe
                )
                out_chunk = index_op.new_chunk(
                    [c],
                    shape=(c.shape[0], len(columns)),
                    index=(j, i),
                    dtypes=dtypes,
                    index_value=c.index_value,
                    columns_value=parse_index(pd.Index(columns), store_data=True),
                )
                out_chunks[j].append(out_chunk)
        out_chunks = [item for l in out_chunks for item in l]
        new_op = op.copy()
        nsplits = (in_df.nsplits[0], tuple(column_nsplits))
        return new_op.new_dataframes(
            op.inputs,
            shape=out_df.shape,
            dtypes=out_df.dtypes,
            index_value=out_df.index_value,
            columns_value=out_df.columns_value,
            chunks=out_chunks,
            nsplits=nsplits,
        )