# Buggy code
def tile(cls, op):
    out_df = op.outputs[0]
    in_tensor = op.input
    out_chunks = []
    nsplits = in_tensor.nsplits
    if any(any(np.isnan(ns)) for ns in nsplits):
        raise NotImplementedError("NAN shape is not supported in DataFrame")

    cum_size = [np.cumsum(s) for s in nsplits]
    for in_chunk in in_tensor.chunks:
        out_op = op.copy().reset_key()
        if in_chunk.ndim == 1:
            (i,) = in_chunk.index
            column_stop = 1
            index = (in_chunk.index[0], 0)
            columns_value = parse_index(
                out_df.columns.to_pandas()[0:1], store_data=True
            )
        else:
            i, j = in_chunk.index
            column_stop = cum_size[1][j]
            index = in_chunk.index
            columns_value = parse_index(
                out_df.columns.to_pandas()[
                    column_stop - in_chunk.shape[1] : column_stop
                ],
                store_data=True,
            )

        index_stop = cum_size[0][i]
        if out_df.index_value is not None:
            index_value = parse_index(
                out_df.index_value.to_pandas()[
                    index_stop - in_chunk.shape[0] : index_stop
                ],
                store_data=True,
            )
        else:
            index_value = parse_index(
                pd.RangeIndex(start=index_stop - in_chunk.shape[0], stop=index_stop)
            )

        out_op.extra_params["index_stop"] = index_stop
        out_op.extra_params["column_stop"] = column_stop
        out_chunk = out_op.new_chunk(
            [in_chunk],
            shape=in_chunk.shape,
            index=index,
            index_value=index_value,
            columns_value=columns_value,
        )
        out_chunks.append(out_chunk)

    new_op = op.copy()
    return new_op.new_dataframes(
        out_df.inputs,
        out_df.shape,
        dtypes=out_df.dtypes,
        index_value=out_df.index_value,
        columns_value=out_df.columns,
        chunks=out_chunks,
        nsplits=in_tensor.nsplits,
    )


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

In [2]: import mars.tensor as mt

In [3]: df = md.DataFrame(mt.random.rand(10, 3), columns=list('abc'))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-8015891094de> in <module>
----> 1 df = md.DataFrame(mt.random.rand(10, 3), columns=list('abc'))

~/Workspace/mars/mars/dataframe/initializer.py in __init__(self, data, index, columns, dtype, copy, chunk_size, gpu, sparse)
29                  chunk_size=None, gpu=None, sparse=None):
30         if isinstance(data, TENSOR_TYPE):
---> 31             df = from_tensor(data, index=index, columns=columns, gpu=gpu, sparse=sparse)
32         elif isinstance(data, DATAFRAME_TYPE):
33             df = data

~/Workspace/mars/mars/dataframe/datasource/from_tensor.py in from_tensor(tensor, index, columns, gpu, sparse)
135     gpu = tensor.op.gpu if gpu is None else gpu
136     op = DataFrameFromTensor(dtypes=pd.Series([tensor.dtype] * col_num), gpu=gpu, sparse=sparse)
--> 137     return op(tensor, index, columns)

~/Workspace/mars/mars/dataframe/datasource/from_tensor.py in __call__(self, input_tensor, index, columns)
51     def __call__(self, input_tensor, index, columns):
52         if index is not None or columns is not None:
---> 53             if input_tensor.shape != (len(index), len(columns)):
54                 raise ValueError(
55                     '({0},{1}) should have the same shape with tensor: {2}'.format(index, columns, input_tensor.shape))

TypeError: object of type 'NoneType' has no len()

# Fixed code
def tile(cls, op):
    out_df = op.outputs[0]
    in_tensor = op.input
    out_chunks = []
    nsplits = in_tensor.nsplits
    if any(any(np.isnan(ns)) for ns in nsplits):
        raise NotImplementedError("NAN shape is not supported in DataFrame")

    cum_size = [np.cumsum(s) for s in nsplits]
    for in_chunk in in_tensor.chunks:
        out_op = op.copy().reset_key()
        if in_chunk.ndim == 1:
            (i,) = in_chunk.index
            column_stop = 1
            index = (in_chunk.index[0], 0)
            columns_value = parse_index(
                out_df.columns.to_pandas()[0:1], store_data=True
            )
        else:
            i, j = in_chunk.index
            column_stop = cum_size[1][j]
            index = in_chunk.index
            columns_value = parse_index(
                out_df.columns.to_pandas()[
                    column_stop - in_chunk.shape[1] : column_stop
                ],
                store_data=True,
            )

        index_stop = cum_size[0][i]
        if out_df.index_value.has_value():
            index_value = parse_index(
                out_df.index_value.to_pandas()[
                    index_stop - in_chunk.shape[0] : index_stop
                ],
                store_data=True,
            )
        else:
            index_value = parse_index(
                pd.RangeIndex(start=index_stop - in_chunk.shape[0], stop=index_stop)
            )

        out_op.extra_params["index_stop"] = index_stop
        out_op.extra_params["column_stop"] = column_stop
        out_chunk = out_op.new_chunk(
            [in_chunk],
            shape=in_chunk.shape,
            index=index,
            index_value=index_value,
            columns_value=columns_value,
        )
        out_chunks.append(out_chunk)

    new_op = op.copy()
    return new_op.new_dataframes(
        out_df.inputs,
        out_df.shape,
        dtypes=out_df.dtypes,
        index_value=out_df.index_value,
        columns_value=out_df.columns,
        chunks=out_chunks,
        nsplits=in_tensor.nsplits,
    )