# Buggy code
def execute(cls, ctx, op):
    inputs = [ctx[c.key] for c in op.inputs]
    xdf = pd if isinstance(inputs[0], (pd.DataFrame, pd.Series)) else cudf

    a = xdf.concat(inputs, axis=op.axis)
    p = len(inputs)
    assert a.shape[op.axis] == p**2

    slc = np.linspace(p - 1, a.shape[op.axis] - 1, num=p - 1, endpoint=False).astype(
        int
    )
    if op.axis == 1:
        slc = (slice(None), slc)
    if op.sort_type == "sort_values":
        a = execute_sort_values(a, op, inplace=False)
        ctx[op.outputs[-1].key] = a.iloc[slc]
    else:
        a = execute_sort_index(a, op, inplace=False)
        ctx[op.outputs[-1].key] = a.index[slc]


# 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(cls, ctx, op):
    inputs = [ctx[c.key] for c in op.inputs if len(ctx[c.key]) > 0]
    if len(inputs) == 0:
        # corner case: nothing sampled, we need to do nothing
        ctx[op.outputs[-1].key] = ctx[op.inputs[0].key]
        return

    xdf = pd if isinstance(inputs[0], (pd.DataFrame, pd.Series)) else cudf

    a = xdf.concat(inputs, axis=op.axis)
    p = len(inputs)
    assert a.shape[op.axis] == p * len(op.inputs)

    slc = np.linspace(
        p - 1, a.shape[op.axis] - 1, num=len(op.inputs) - 1, endpoint=False
    ).astype(int)
    if op.axis == 1:
        slc = (slice(None), slc)
    if op.sort_type == "sort_values":
        a = execute_sort_values(a, op, inplace=False)
        ctx[op.outputs[-1].key] = a.iloc[slc]
    else:
        a = execute_sort_index(a, op, inplace=False)
        ctx[op.outputs[-1].key] = a.index[slc]