# Buggy code
def __call__(self, groupby, dtypes=None, index=None):
    in_df = groupby
    while in_df.op.output_types[0] not in (OutputType.dataframe, OutputType.series):
        in_df = in_df.inputs[0]

    dtypes, index_value = self._infer_df_func_returns(groupby, in_df, dtypes, index)
    for arg, desc in zip(
        (self.output_types, dtypes, index_value), ("output_types", "dtypes", "index")
    ):
        if arg is None:
            raise TypeError(
                f"Cannot determine {desc} by calculating with enumerate data, "
                "please specify it as arguments"
            )

    if self.output_types[0] == OutputType.dataframe:
        new_shape = (np.nan, len(dtypes))
        return self.new_dataframe(
            [groupby],
            shape=new_shape,
            dtypes=dtypes,
            index_value=index_value,
            columns_value=parse_index(dtypes.index, store_data=True),
        )
    else:
        name, dtype = dtypes
        new_shape = (np.nan,)
        return self.new_series(
            [groupby], name=name, shape=new_shape, dtype=dtype, index_value=index_value
        )


# Traceback (AssertionError)
Traceback (most recent call last):
File "/Users/wenjun/miniconda3/lib/python3.8/unittest/case.py", line 60, in testPartExecutor
yield
File "/Users/wenjun/miniconda3/lib/python3.8/unittest/case.py", line 676, in run
self._callTestMethod(testMethod)
File "/Users/wenjun/miniconda3/lib/python3.8/unittest/case.py", line 633, in _callTestMethod
method()
File "/Users/wenjun/Code/mars/mars/dataframe/groupby/tests/test_groupby_execution.py", line 401, in testGroupByApply
pd.testing.assert_frame_equal(self.executor.execute_dataframe(applied, concat=True)[0],
File "/Users/wenjun/Code/mars/mars/tests/core.py", line 686, in execute_tileable
result = super().execute_tileable(tileable, *args, **kwargs)
File "/Users/wenjun/Code/mars/mars/utils.py", line 439, in _inner
return func(*args, **kwargs)
File "/Users/wenjun/Code/mars/mars/executor.py", line 720, in execute_tileable
ret = self.execute_graph(chunk_graph, result_keys, n_parallel=n_parallel or n_thread,
File "/Users/wenjun/Code/mars/mars/tests/core.py", line 673, in execute_graph
return super().execute_graph(graph, keys, **kw)
File "/Users/wenjun/Code/mars/mars/executor.py", line 693, in execute_graph
res = graph_execution.execute(retval)
File "/Users/wenjun/Code/mars/mars/executor.py", line 574, in execute
future.result()
File "/Users/wenjun/miniconda3/lib/python3.8/concurrent/futures/_base.py", line 439, in result
return self.__get_result()
File "/Users/wenjun/miniconda3/lib/python3.8/concurrent/futures/_base.py", line 388, in __get_result
raise self._exception
File "/Users/wenjun/miniconda3/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/Users/wenjun/Code/mars/mars/tests/core.py", line 591, in _execute_operand
super()._execute_operand(op)
File "/Users/wenjun/Code/mars/mars/utils.py", line 439, in _inner
return func(*args, **kwargs)
File "/Users/wenjun/Code/mars/mars/executor.py", line 446, in _execute_operand
self.handle_op(first_op, results, self._mock)
File "/Users/wenjun/Code/mars/mars/executor.py", line 378, in handle_op
return Executor.handle(*args, **kw)
File "/Users/wenjun/Code/mars/mars/executor.py", line 644, in handle
return runner(results, op)
File "/Users/wenjun/Code/mars/mars/dataframe/groupby/apply.py", line 63, in execute
assert len(applied.index) == 1
AssertionError

# Fixed code
def __call__(self, groupby, dtypes=None, index=None):
    in_df = groupby
    while in_df.op.output_types[0] not in (OutputType.dataframe, OutputType.series):
        in_df = in_df.inputs[0]

    dtypes, index_value = self._infer_df_func_returns(groupby, in_df, dtypes, index)
    if index_value is None:
        index_value = parse_index(None, (in_df.key, in_df.index_value.key))
    for arg, desc in zip((self.output_types, dtypes), ("output_types", "dtypes")):
        if arg is None:
            raise TypeError(
                f"Cannot determine {desc} by calculating with enumerate data, "
                "please specify it as arguments"
            )

    if self.output_types[0] == OutputType.dataframe:
        new_shape = (np.nan, len(dtypes))
        return self.new_dataframe(
            [groupby],
            shape=new_shape,
            dtypes=dtypes,
            index_value=index_value,
            columns_value=parse_index(dtypes.index, store_data=True),
        )
    else:
        name, dtype = dtypes
        new_shape = (np.nan,)
        return self.new_series(
            [groupby], name=name, shape=new_shape, dtype=dtype, index_value=index_value
        )