# Buggy code
def _calc_properties(cls, x1, x2=None, axis="columns"):
    if isinstance(x1, (DATAFRAME_TYPE, DATAFRAME_CHUNK_TYPE)) and (
        x2 is None or np.isscalar(x2) or isinstance(x2, TENSOR_TYPE)
    ):
        if x2 is None:
            dtypes = x1.dtypes
        elif np.isscalar(x2):
            dtypes = infer_dtypes(
                x1.dtypes, pd.Series(np.array(x2).dtype), cls._operator
            )
        elif x1.dtypes is not None and isinstance(x2, TENSOR_TYPE):
            dtypes = pd.Series(
                [infer_dtype(dt, x2.dtype, cls._operator) for dt in x1.dtypes],
                index=x1.dtypes.index,
            )
        else:
            dtypes = x1.dtypes
        return {
            "shape": x1.shape,
            "dtypes": dtypes,
            "columns_value": x1.columns_value,
            "index_value": x1.index_value,
        }

    if isinstance(x1, (SERIES_TYPE, SERIES_CHUNK_TYPE)) and (
        x2 is None or np.isscalar(x2) or isinstance(x2, TENSOR_TYPE)
    ):
        x2_dtype = x2.dtype if hasattr(x2, "dtype") else type(x2)
        dtype = infer_dtype(x1.dtype, np.dtype(x2_dtype), cls._operator)
        return {"shape": x1.shape, "dtype": dtype, "index_value": x1.index_value}

    if isinstance(x1, (DATAFRAME_TYPE, DATAFRAME_CHUNK_TYPE)) and isinstance(
        x2, (DATAFRAME_TYPE, DATAFRAME_CHUNK_TYPE)
    ):
        index_shape, column_shape, dtypes, columns, index = (
            np.nan,
            np.nan,
            None,
            None,
            None,
        )

        if (
            x1.columns_value is not None
            and x2.columns_value is not None
            and x1.columns_value.key == x2.columns_value.key
        ):
            dtypes = pd.Series(
                [
                    infer_dtype(dt1, dt2, cls._operator)
                    for dt1, dt2 in zip(x1.dtypes, x2.dtypes)
                ],
                index=x1.dtypes.index,
            )
            columns = copy.copy(x1.columns_value)
            columns.value.should_be_monotonic = False
            column_shape = len(dtypes)
        elif x1.dtypes is not None and x2.dtypes is not None:
            dtypes = infer_dtypes(x1.dtypes, x2.dtypes, cls._operator)
            columns = parse_index(dtypes.index, store_data=True)
            columns.value.should_be_monotonic = True
            column_shape = len(dtypes)
        if x1.index_value is not None and x2.index_value is not None:
            if x1.index_value.key == x2.index_value.key:
                index = copy.copy(x1.index_value)
                index.value.should_be_monotonic = False
                index_shape = x1.shape[0]
            else:
                index = infer_index_value(x1.index_value, x2.index_value)
                index.value.should_be_monotonic = True
                if index.key == x1.index_value.key == x2.index_value.key and (
                    not np.isnan(x1.shape[0]) or not np.isnan(x2.shape[0])
                ):
                    index_shape = (
                        x1.shape[0] if not np.isnan(x1.shape[0]) else x2.shape[0]
                    )

        return {
            "shape": (index_shape, column_shape),
            "dtypes": dtypes,
            "columns_value": columns,
            "index_value": index,
        }

    if isinstance(x1, (DATAFRAME_TYPE, DATAFRAME_CHUNK_TYPE)) and isinstance(
        x2, (SERIES_TYPE, SERIES_CHUNK_TYPE)
    ):
        if axis == "columns" or axis == 1:
            index_shape = x1.shape[0]
            index = x1.index_value
            column_shape, dtypes, columns = np.nan, None, None
            if x1.columns_value is not None and x1.index_value is not None:
                if x1.columns_value.key == x2.index_value.key:
                    dtypes = pd.Series(
                        [infer_dtype(dt, x2.dtype, cls._operator) for dt in x1.dtypes],
                        index=x1.dtypes.index,
                    )
                    columns = copy.copy(x1.columns_value)
                    columns.value.should_be_monotonic = False
                    column_shape = len(dtypes)
                else:  # pragma: no cover
                    dtypes = x1.dtypes  # FIXME
                    columns = infer_index_value(x1.columns_value, x2.index_value)
                    columns.value.should_be_monotonic = True
                    column_shape = np.nan
        else:
            assert axis == "index" or axis == 0
            column_shape = x1.shape[1]
            columns = x1.columns_value
            dtypes = x1.dtypes
            index_shape, index = np.nan, None
            if x1.index_value is not None and x1.index_value is not None:
                if x1.index_value.key == x2.index_value.key:
                    dtypes = pd.Series(
                        [infer_dtype(dt, x2.dtype, cls._operator) for dt in x1.dtypes],
                        index=x1.dtypes.index,
                    )
                    index = copy.copy(x1.index_value)
                    index.value.should_be_monotonic = False
                    index_shape = x1.shape[0]
                else:
                    if x1.dtypes is not None:
                        dtypes = pd.Series(
                            [
                                infer_dtype(dt, x2.dtype, cls._operator)
                                for dt in x1.dtypes
                            ],
                            index=x1.dtypes.index,
                        )
                    index = infer_index_value(x1.index_value, x2.index_value)
                    index.value.should_be_monotonic = True
                    index_shape = np.nan
        return {
            "shape": (index_shape, column_shape),
            "dtypes": dtypes,
            "columns_value": columns,
            "index_value": index,
        }

    if isinstance(x1, (SERIES_TYPE, SERIES_CHUNK_TYPE)) and isinstance(
        x2, (SERIES_TYPE, SERIES_CHUNK_TYPE)
    ):
        index_shape, dtype, index = np.nan, None, None

        dtype = infer_dtype(x1.dtype, x2.dtype, cls._operator)
        if x1.index_value is not None and x2.index_value is not None:
            if x1.index_value.key == x2.index_value.key:
                index = copy.copy(x1.index_value)
                index.value.should_be_monotonic = False
                index_shape = x1.shape[0]
            else:
                index = infer_index_value(x1.index_value, x2.index_value)
                index.value.should_be_monotonic = True
                if index.key == x1.index_value.key == x2.index_value.key and (
                    not np.isnan(x1.shape[0]) or not np.isnan(x2.shape[0])
                ):
                    index_shape = (
                        x1.shape[0] if not np.isnan(x1.shape[0]) else x2.shape[0]
                    )

        return {"shape": (index_shape,), "dtype": dtype, "index_value": index}

    raise NotImplementedError("Unknown combination of parameters")


# 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 _calc_properties(cls, x1, x2=None, axis="columns"):
    if isinstance(x1, (DATAFRAME_TYPE, DATAFRAME_CHUNK_TYPE)) and (
        x2 is None or pd.api.types.is_scalar(x2) or isinstance(x2, TENSOR_TYPE)
    ):
        if x2 is None:
            dtypes = x1.dtypes
        elif pd.api.types.is_scalar(x2):
            dtypes = infer_dtypes(
                x1.dtypes, pd.Series(np.array(x2).dtype), cls._operator
            )
        elif x1.dtypes is not None and isinstance(x2, TENSOR_TYPE):
            dtypes = pd.Series(
                [infer_dtype(dt, x2.dtype, cls._operator) for dt in x1.dtypes],
                index=x1.dtypes.index,
            )
        else:
            dtypes = x1.dtypes
        return {
            "shape": x1.shape,
            "dtypes": dtypes,
            "columns_value": x1.columns_value,
            "index_value": x1.index_value,
        }

    if isinstance(x1, (SERIES_TYPE, SERIES_CHUNK_TYPE)) and (
        x2 is None or pd.api.types.is_scalar(x2) or isinstance(x2, TENSOR_TYPE)
    ):
        x2_dtype = x2.dtype if hasattr(x2, "dtype") else type(x2)
        dtype = infer_dtype(x1.dtype, np.dtype(x2_dtype), cls._operator)
        return {"shape": x1.shape, "dtype": dtype, "index_value": x1.index_value}

    if isinstance(x1, (DATAFRAME_TYPE, DATAFRAME_CHUNK_TYPE)) and isinstance(
        x2, (DATAFRAME_TYPE, DATAFRAME_CHUNK_TYPE)
    ):
        index_shape, column_shape, dtypes, columns, index = (
            np.nan,
            np.nan,
            None,
            None,
            None,
        )

        if (
            x1.columns_value is not None
            and x2.columns_value is not None
            and x1.columns_value.key == x2.columns_value.key
        ):
            dtypes = pd.Series(
                [
                    infer_dtype(dt1, dt2, cls._operator)
                    for dt1, dt2 in zip(x1.dtypes, x2.dtypes)
                ],
                index=x1.dtypes.index,
            )
            columns = copy.copy(x1.columns_value)
            columns.value.should_be_monotonic = False
            column_shape = len(dtypes)
        elif x1.dtypes is not None and x2.dtypes is not None:
            dtypes = infer_dtypes(x1.dtypes, x2.dtypes, cls._operator)
            columns = parse_index(dtypes.index, store_data=True)
            columns.value.should_be_monotonic = True
            column_shape = len(dtypes)
        if x1.index_value is not None and x2.index_value is not None:
            if x1.index_value.key == x2.index_value.key:
                index = copy.copy(x1.index_value)
                index.value.should_be_monotonic = False
                index_shape = x1.shape[0]
            else:
                index = infer_index_value(x1.index_value, x2.index_value)
                index.value.should_be_monotonic = True
                if index.key == x1.index_value.key == x2.index_value.key and (
                    not np.isnan(x1.shape[0]) or not np.isnan(x2.shape[0])
                ):
                    index_shape = (
                        x1.shape[0] if not np.isnan(x1.shape[0]) else x2.shape[0]
                    )

        return {
            "shape": (index_shape, column_shape),
            "dtypes": dtypes,
            "columns_value": columns,
            "index_value": index,
        }

    if isinstance(x1, (DATAFRAME_TYPE, DATAFRAME_CHUNK_TYPE)) and isinstance(
        x2, (SERIES_TYPE, SERIES_CHUNK_TYPE)
    ):
        if axis == "columns" or axis == 1:
            index_shape = x1.shape[0]
            index = x1.index_value
            column_shape, dtypes, columns = np.nan, None, None
            if x1.columns_value is not None and x1.index_value is not None:
                if x1.columns_value.key == x2.index_value.key:
                    dtypes = pd.Series(
                        [infer_dtype(dt, x2.dtype, cls._operator) for dt in x1.dtypes],
                        index=x1.dtypes.index,
                    )
                    columns = copy.copy(x1.columns_value)
                    columns.value.should_be_monotonic = False
                    column_shape = len(dtypes)
                else:  # pragma: no cover
                    dtypes = x1.dtypes  # FIXME
                    columns = infer_index_value(x1.columns_value, x2.index_value)
                    columns.value.should_be_monotonic = True
                    column_shape = np.nan
        else:
            assert axis == "index" or axis == 0
            column_shape = x1.shape[1]
            columns = x1.columns_value
            dtypes = x1.dtypes
            index_shape, index = np.nan, None
            if x1.index_value is not None and x1.index_value is not None:
                if x1.index_value.key == x2.index_value.key:
                    dtypes = pd.Series(
                        [infer_dtype(dt, x2.dtype, cls._operator) for dt in x1.dtypes],
                        index=x1.dtypes.index,
                    )
                    index = copy.copy(x1.index_value)
                    index.value.should_be_monotonic = False
                    index_shape = x1.shape[0]
                else:
                    if x1.dtypes is not None:
                        dtypes = pd.Series(
                            [
                                infer_dtype(dt, x2.dtype, cls._operator)
                                for dt in x1.dtypes
                            ],
                            index=x1.dtypes.index,
                        )
                    index = infer_index_value(x1.index_value, x2.index_value)
                    index.value.should_be_monotonic = True
                    index_shape = np.nan
        return {
            "shape": (index_shape, column_shape),
            "dtypes": dtypes,
            "columns_value": columns,
            "index_value": index,
        }

    if isinstance(x1, (SERIES_TYPE, SERIES_CHUNK_TYPE)) and isinstance(
        x2, (SERIES_TYPE, SERIES_CHUNK_TYPE)
    ):
        index_shape, dtype, index = np.nan, None, None

        dtype = infer_dtype(x1.dtype, x2.dtype, cls._operator)
        if x1.index_value is not None and x2.index_value is not None:
            if x1.index_value.key == x2.index_value.key:
                index = copy.copy(x1.index_value)
                index.value.should_be_monotonic = False
                index_shape = x1.shape[0]
            else:
                index = infer_index_value(x1.index_value, x2.index_value)
                index.value.should_be_monotonic = True
                if index.key == x1.index_value.key == x2.index_value.key and (
                    not np.isnan(x1.shape[0]) or not np.isnan(x2.shape[0])
                ):
                    index_shape = (
                        x1.shape[0] if not np.isnan(x1.shape[0]) else x2.shape[0]
                    )

        return {"shape": (index_shape,), "dtype": dtype, "index_value": index}

    raise NotImplementedError("Unknown combination of parameters")