# Buggy code
def _execute_reduce(cls, ctx, op):
    input_keys, _ = get_shuffle_input_keys_idxes(op.inputs[0])
    if getattr(ctx, "running_mode", None) == RunningMode.distributed:
        raw_inputs = [ctx.pop((input_key, op.shuffle_key)) for input_key in input_keys]
    else:
        raw_inputs = [ctx[(input_key, op.shuffle_key)] for input_key in input_keys]

    xdf = pd if isinstance(raw_inputs[0], (pd.DataFrame, pd.Series)) else cudf
    if xdf is pd:
        concat_values = xdf.concat(raw_inputs, axis=op.axis, copy=False)
    else:
        concat_values = xdf.concat(raw_inputs, axis=op.axis)
    del raw_inputs[:]

    if isinstance(concat_values, xdf.DataFrame):
        concat_values.drop(_PSRS_DISTINCT_COL, axis=1, inplace=True, errors="ignore")

    if op.sort_type == "sort_values":
        ctx[op.outputs[0].key] = execute_sort_values(concat_values, op)
    else:
        ctx[op.outputs[0].key] = execute_sort_index(concat_values, op)


# 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 _execute_reduce(cls, ctx, op):
    out_chunk = op.outputs[0]
    input_keys, _ = get_shuffle_input_keys_idxes(op.inputs[0])
    if getattr(ctx, "running_mode", None) == RunningMode.distributed:
        raw_inputs = [ctx.pop((input_key, op.shuffle_key)) for input_key in input_keys]
    else:
        raw_inputs = [ctx[(input_key, op.shuffle_key)] for input_key in input_keys]

    xdf = pd if isinstance(raw_inputs[0], (pd.DataFrame, pd.Series)) else cudf
    if xdf is pd:
        concat_values = xdf.concat(raw_inputs, axis=op.axis, copy=False)
    else:
        concat_values = xdf.concat(raw_inputs, axis=op.axis)
    del raw_inputs[:]

    if isinstance(concat_values, xdf.DataFrame):
        concat_values.drop(_PSRS_DISTINCT_COL, axis=1, inplace=True, errors="ignore")

        col_index_dtype = out_chunk.columns_value.to_pandas().dtype
        if concat_values.columns.dtype != col_index_dtype:
            concat_values.columns = concat_values.columns.astype(col_index_dtype)

    if op.sort_type == "sort_values":
        ctx[op.outputs[0].key] = execute_sort_values(concat_values, op)
    else:
        ctx[op.outputs[0].key] = execute_sort_index(concat_values, op)