# Buggy code
def __init__(
    self,
    data=None,
    dtype=None,
    copy=False,
    name=None,
    tupleize_cols=True,
    chunk_size=None,
    gpu=None,
    sparse=None,
    names=None,
    num_partitions=None,
):
    # make sure __getattr__ does not result in stack overflow
    self._data = None

    need_repart = False
    if isinstance(data, INDEX_TYPE):
        if not hasattr(data, "data"):
            # IndexData
            index = _Index(data)
        else:
            index = data
        need_repart = num_partitions is not None
    else:
        if isinstance(data, (Base, Entity)):
            name = name if name is not None else getattr(data, "name", None)
            index = from_tileable_index(data, dtype=dtype, name=name)
            need_repart = num_partitions is not None
        else:
            if not isinstance(data, pd.Index):
                name = name if name is not None else getattr(data, "name", None)
                pd_index = pd.Index(
                    data=data,
                    dtype=dtype,
                    copy=copy,
                    name=name,
                    tupleize_cols=tupleize_cols,
                )
            else:
                pd_index = data

            if num_partitions is not None:
                chunk_size = ceildiv(len(pd_index), num_partitions)
            index = from_pandas_index(
                pd_index, chunk_size=chunk_size, gpu=gpu, sparse=sparse
            )

    if need_repart:
        index = index.rebalance(num_partitions=num_partitions)
    super().__init__(index.data)


# Traceback (ZeroDivisionError)
Traceback (most recent call last):
File "/Users/wenjun.swj/miniconda3/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3417, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-6-f86c22f8381d>", line 1, in <module>
mdf[mdf[0] != 0].sort_values(0).execute()
File "/Users/wenjun.swj/Code/mars/mars/core.py", line 646, in execute
return run()
File "/Users/wenjun.swj/Code/mars/mars/core.py", line 642, in run
self.data.execute(session, **kw)
File "/Users/wenjun.swj/Code/mars/mars/core.py", line 379, in execute
return run()
File "/Users/wenjun.swj/Code/mars/mars/core.py", line 374, in run
session.run(self, **kw)
File "/Users/wenjun.swj/Code/mars/mars/session.py", line 505, in run
result = self._sess.run(*tileables, **kw)
File "/Users/wenjun.swj/Code/mars/mars/session.py", line 111, in run
res = self._executor.execute_tileables(tileables, **kw)
File "/Users/wenjun.swj/Code/mars/mars/utils.py", line 457, in _inner
return func(*args, **kwargs)
File "/Users/wenjun.swj/Code/mars/mars/executor.py", line 883, in execute_tileables
self.execute_graph(chunk_graph, list(temp_result_keys),
File "/Users/wenjun.swj/Code/mars/mars/executor.py", line 698, in execute_graph
res = graph_execution.execute(retval)
File "/Users/wenjun.swj/Code/mars/mars/executor.py", line 579, in execute
future.result()
File "/Users/wenjun.swj/miniconda3/lib/python3.8/concurrent/futures/_base.py", line 432, in result
return self.__get_result()
File "/Users/wenjun.swj/miniconda3/lib/python3.8/concurrent/futures/_base.py", line 388, in __get_result
raise self._exception
File "/Users/wenjun.swj/miniconda3/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/Users/wenjun.swj/Code/mars/mars/utils.py", line 457, in _inner
return func(*args, **kwargs)
File "/Users/wenjun.swj/Code/mars/mars/executor.py", line 446, in _execute_operand
self.handle_op(first_op, results, self._mock)
File "/Users/wenjun.swj/Code/mars/mars/executor.py", line 378, in handle_op
return Executor.handle(*args, **kw)
File "/Users/wenjun.swj/Code/mars/mars/executor.py", line 649, in handle
return runner(results, op)
File "/Users/wenjun.swj/Code/mars/mars/dataframe/sort/psrs.py", line 355, in execute
num = n // a.shape[op.axis] + 1
ZeroDivisionError: integer division or modulo by zero

# Fixed code
def __init__(
    self,
    data=None,
    dtype=None,
    copy=False,
    name=None,
    tupleize_cols=True,
    chunk_size=None,
    gpu=None,
    sparse=None,
    names=None,
    num_partitions=None,
):
    # make sure __getattr__ does not result in stack overflow
    self._data = None

    need_repart = False
    if isinstance(data, INDEX_TYPE):
        if not hasattr(data, "data"):
            # IndexData
            index = _Index(data)
        else:
            index = data
        need_repart = num_partitions is not None
    else:
        if isinstance(data, (Base, Entity)):
            name = name if name is not None else getattr(data, "name", None)
            index = from_tileable_index(data, dtype=dtype, name=name, names=names)
            need_repart = num_partitions is not None
        else:
            if not isinstance(data, pd.Index):
                name = name if name is not None else getattr(data, "name", None)
                pd_index = pd.Index(
                    data=data,
                    dtype=dtype,
                    copy=copy,
                    name=name,
                    tupleize_cols=tupleize_cols,
                )
            else:
                pd_index = data

            if num_partitions is not None:
                chunk_size = ceildiv(len(pd_index), num_partitions)
            index = from_pandas_index(
                pd_index, chunk_size=chunk_size, gpu=gpu, sparse=sparse
            )

    if need_repart:
        index = index.rebalance(num_partitions=num_partitions)
    super().__init__(index.data)