# Buggy code
def _tile_dataframe(cls, op):
    in_df = op.inputs[0]
    out_df = op.outputs[0]
    added_columns_num = len(out_df.dtypes) - len(in_df.dtypes)
    out_chunks = []
    is_range_index = out_df.index_value.has_value()
    cum_range = np.cumsum((0,) + in_df.nsplits[0])
    for c in in_df.chunks:
        if is_range_index:
            index_value = parse_index(
                pd.RangeIndex(cum_range[c.index[0]], cum_range[c.index[0] + 1])
            )
        else:
            index_value = out_df.index_value
        if c.index[1] == 0:
            chunk_op = op.copy().reset_key()
            dtypes = out_df.dtypes[: (added_columns_num + len(c.dtypes))]
            columns_value = parse_index(dtypes.index)
            new_chunk = chunk_op.new_chunk(
                [c],
                shape=(c.shape[0], c.shape[1] + added_columns_num),
                index=c.index,
                index_value=index_value,
                columns_value=columns_value,
                dtypes=dtypes,
            )
        else:
            chunk_op = op.copy().reset_key()
            chunk_op._drop = True
            new_chunk = chunk_op.new_chunk(
                [c],
                shape=c.shape,
                index_value=index_value,
                index=c.index,
                columns_value=c.columns_value,
                dtypes=c.dtypes,
            )
        out_chunks.append(new_chunk)
    if not is_range_index and isinstance(
        out_df.index_value._index_value, IndexValue.RangeIndex
    ):
        out_chunks = standardize_range_index(out_chunks)
    new_op = op.copy()
    columns_splits = list(in_df.nsplits[1])
    columns_splits[0] += added_columns_num
    nsplits = (in_df.nsplits[0], tuple(columns_splits))
    return new_op.new_dataframes(
        op.inputs,
        out_df.shape,
        nsplits=nsplits,
        chunks=out_chunks,
        dtypes=out_df.dtypes,
        index_value=out_df.index_value,
        columns_value=out_df.columns_value,
    )


# Traceback (TypeError)
In [25]: df = md.DataFrame(mt.random.rand(10, 3), chunk_size=3)

In [26]: df.sort_values(0).reset_index(drop=True).execute()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-26-e0c111d55eb4> in <module>
----> 1 df.sort_values(0).reset_index(drop=True).execute()

~/Documents/mars_dev/mars/mars/core.py in execute(self, session, **kw)
559
560     def execute(self, session=None, **kw):
--> 561         self._data.execute(session, **kw)
562         return self
563

~/Documents/mars_dev/mars/mars/core.py in execute(self, session, **kw)
368
369         # no more fetch, thus just fire run
--> 370         session.run(self, **kw)
371         # return Tileable or ExecutableTuple itself
372         return self

~/Documents/mars_dev/mars/mars/session.py in run(self, *tileables, **kw)
430         tileables = tuple(mt.tensor(t) if not isinstance(t, (Entity, Base)) else t
431                           for t in tileables)
--> 432         result = self._sess.run(*tileables, **kw)
433
434         for t in tileables:

~/Documents/mars_dev/mars/mars/session.py in run(self, *tileables, **kw)
98             # set number of running cores
99             self.context.set_ncores(kw['n_parallel'])
--> 100             res = self._executor.execute_tileables(tileables, **kw)
101             return res
102

~/Documents/mars_dev/mars/mars/utils.py in _wrapped(*args, **kwargs)
383                 _kernel_mode.eager = False
384             _kernel_mode.eager_count = enter_eager_count + 1
--> 385             return func(*args, **kwargs)
386         finally:
387             _kernel_mode.eager_count -= 1

~/Documents/mars_dev/mars/mars/utils.py in inner(*args, **kwargs)
471     def inner(*args, **kwargs):
472         with build_mode():
--> 473             return func(*args, **kwargs)
474     return inner
475

~/Documents/mars_dev/mars/mars/executor.py in execute_tileables(self, tileables, fetch, n_parallel, n_thread, print_progress, mock, compose)
817                 # build chunk graph, tile will be done during building
818                 chunk_graph = chunk_graph_builder.build(
--> 819                     tileables, tileable_graph=tileable_graph)
820                 tileable_graph = chunk_graph_builder.prev_tileable_graph
821                 temp_result_keys = set(result_keys)

~/Documents/mars_dev/mars/mars/utils.py in _wrapped(*args, **kwargs)
383                 _kernel_mode.eager = False
384             _kernel_mode.eager_count = enter_eager_count + 1
--> 385             return func(*args, **kwargs)
386         finally:
387             _kernel_mode.eager_count -= 1

~/Documents/mars_dev/mars/mars/utils.py in inner(*args, **kwargs)
471     def inner(*args, **kwargs):
472         with build_mode():
--> 473             return func(*args, **kwargs)
474     return inner
475

~/Documents/mars_dev/mars/mars/tiles.py in build(self, tileables, tileable_graph)
340
341         chunk_graph = super().build(
--> 342             tileables, tileable_graph=tileable_graph)
343         self._iterative_chunk_graphs.append(chunk_graph)
344         if len(self._interrupted_ops) == 0:

~/Documents/mars_dev/mars/mars/utils.py in _wrapped(*args, **kwargs)
383                 _kernel_mode.eager = False
384             _kernel_mode.eager_count = enter_eager_count + 1
--> 385             return func(*args, **kwargs)
386         finally:
387             _kernel_mode.eager_count -= 1

~/Documents/mars_dev/mars/mars/utils.py in inner(*args, **kwargs)
471     def inner(*args, **kwargs):
472         with build_mode():
--> 473             return func(*args, **kwargs)
474     return inner
475

~/Documents/mars_dev/mars/mars/tiles.py in build(self, tileables, tileable_graph)
253                     # for further execution
254                     partial_tiled_chunks = \
--> 255                         self._on_tile_failure(tileable_data.op, exc_info)
256                     if partial_tiled_chunks is not None and \
257                             len(partial_tiled_chunks) > 0:

~/Documents/mars_dev/mars/mars/tiles.py in inner(op, exc_info)
292                     on_tile_failure(op, exc_info)
293                 else:
--> 294                     raise exc_info[1].with_traceback(exc_info[2]) from None
295         return inner
296

~/Documents/mars_dev/mars/mars/tiles.py in build(self, tileables, tileable_graph)
233                 continue
234             try:
--> 235                 tiled = self._tile(tileable_data, tileable_graph)
236                 tiled_op.add(tileable_data.op)
237                 for t, td in zip(tileable_data.op.outputs, tiled):

~/Documents/mars_dev/mars/mars/tiles.py in _tile(self, tileable_data, tileable_graph)
328         if any(inp.op in self._interrupted_ops for inp in tileable_data.inputs):
329             raise TilesError('Tile fail due to failure of inputs')
--> 330         return super()._tile(tileable_data, tileable_graph)
331
332     @kernel_mode

~/Documents/mars_dev/mars/mars/tiles.py in _tile(self, tileable_data, tileable_graph)
191                 t._nsplits = o.nsplits
192         elif on_tile is None:
--> 193             tds[0]._inplace_tile()
194         else:
195             tds = on_tile(tileable_data.op.outputs, tds)

~/Documents/mars_dev/mars/mars/core.py in _inplace_tile(self)
160
161     def _inplace_tile(self):
--> 162         return handler.inplace_tile(self)
163
164     def __getattr__(self, attr):

~/Documents/mars_dev/mars/mars/tiles.py in inplace_tile(self, to_tile)
126         if not to_tile.is_coarse():
127             return to_tile
--> 128         dispatched = self.dispatch(to_tile.op)
129         self._assign_to([d.data for d in dispatched], to_tile.op.outputs)
130         return to_tile

~/Documents/mars_dev/mars/mars/utils.py in _wrapped(*args, **kwargs)
383                 _kernel_mode.eager = False
384             _kernel_mode.eager_count = enter_eager_count + 1
--> 385             return func(*args, **kwargs)
386         finally:
387             _kernel_mode.eager_count -= 1

~/Documents/mars_dev/mars/mars/tiles.py in dispatch(self, op)
113             return self._handlers[op_cls](op)
114         try:
--> 115             return op_cls.tile(op)
116         except NotImplementedError as ex:
117             cause = ex

~/Documents/mars_dev/mars/mars/dataframe/base/reset_index.py in tile(cls, op)
130     def tile(cls, op):
131         if isinstance(op.inputs[0], DATAFRAME_TYPE):
--> 132             return cls._tile_dataframe(op)
133         else:
134             return cls._tile_series(op)

~/Documents/mars_dev/mars/mars/dataframe/base/reset_index.py in _tile_dataframe(cls, op)
101         for c in in_df.chunks:
102             if is_range_index:
--> 103                 index_value = parse_index(pd.RangeIndex(cum_range[c.index[0]], cum_range[c.index[0] + 1]))
104             else:
105                 index_value = out_df.index_value

~/miniconda3/lib/python3.7/site-packages/pandas/core/indexes/range.py in __new__(cls, start, stop, step, dtype, copy, name)
102             start, stop = 0, start
103         else:
--> 104             stop = ensure_python_int(stop)
105
106         step = ensure_python_int(step) if step is not None else 1

~/miniconda3/lib/python3.7/site-packages/pandas/core/dtypes/common.py in ensure_python_int(value)
200         assert new_value == value
201     except (TypeError, ValueError, AssertionError):
--> 202         raise TypeError(msg.format(type(value), value))
203     return new_value
204

TypeError: Wrong type <class 'numpy.float64'> for value nan

# Fixed code
def _tile_dataframe(cls, op):
    in_df = op.inputs[0]
    out_df = op.outputs[0]
    added_columns_num = len(out_df.dtypes) - len(in_df.dtypes)
    out_chunks = []
    index_has_value = out_df.index_value.has_value()
    chunk_has_nan = any(np.isnan(s) for s in in_df.nsplits[0])
    cum_range = np.cumsum((0,) + in_df.nsplits[0])
    for c in in_df.chunks:
        if index_has_value:
            if chunk_has_nan:
                index_value = parse_index(pd.RangeIndex(-1))
            else:
                index_value = parse_index(
                    pd.RangeIndex(cum_range[c.index[0]], cum_range[c.index[0] + 1])
                )
        else:
            index_value = out_df.index_value
        if c.index[1] == 0:
            chunk_op = op.copy().reset_key()
            dtypes = out_df.dtypes[: (added_columns_num + len(c.dtypes))]
            columns_value = parse_index(dtypes.index)
            new_chunk = chunk_op.new_chunk(
                [c],
                shape=(c.shape[0], c.shape[1] + added_columns_num),
                index=c.index,
                index_value=index_value,
                columns_value=columns_value,
                dtypes=dtypes,
            )
        else:
            chunk_op = op.copy().reset_key()
            chunk_op._drop = True
            new_chunk = chunk_op.new_chunk(
                [c],
                shape=c.shape,
                index_value=index_value,
                index=c.index,
                columns_value=c.columns_value,
                dtypes=c.dtypes,
            )
        out_chunks.append(new_chunk)
    if not index_has_value or chunk_has_nan:
        if isinstance(out_df.index_value._index_value, IndexValue.RangeIndex):
            out_chunks = standardize_range_index(out_chunks)
    new_op = op.copy()
    columns_splits = list(in_df.nsplits[1])
    columns_splits[0] += added_columns_num
    nsplits = (in_df.nsplits[0], tuple(columns_splits))
    return new_op.new_dataframes(
        op.inputs,
        out_df.shape,
        nsplits=nsplits,
        chunks=out_chunks,
        dtypes=out_df.dtypes,
        index_value=out_df.index_value,
        columns_value=out_df.columns_value,
    )