# Buggy code
def aggregate(self, func=None, *args, **kwargs):
    if self._axis != 0:
        # This is not implemented in pandas,
        # so we throw a different message
        raise NotImplementedError("axis other than 0 is not supported")

    if (
        callable(func)
        and isinstance(func, BuiltinFunctionType)
        and func.__name__ in dir(self)
    ):
        func = func.__name__

    relabeling_required = False
    if isinstance(func, dict) or func is None:

        def try_get_str_func(fn):
            if not isinstance(fn, str) and isinstance(fn, Iterable):
                return [try_get_str_func(f) for f in fn]
            return fn.__name__ if callable(fn) and fn.__name__ in dir(self) else fn

        relabeling_required, func_dict, new_columns, order = reconstruct_func(
            func, **kwargs
        )
        func_dict = {col: try_get_str_func(fn) for col, fn in func_dict.items()}

        if any(i not in self._df.columns for i in func_dict.keys()):
            from pandas.core.base import SpecificationError

            raise SpecificationError("nested renamer is not supported")
        if func is None:
            kwargs = {}
        func = func_dict
    elif is_list_like(func):
        return self._default_to_pandas(
            lambda df, *args, **kwargs: df.aggregate(func, *args, **kwargs),
            *args,
            **kwargs,
        )
    elif callable(func):
        return self._apply_agg_function(
            lambda grp, *args, **kwargs: grp.aggregate(func, *args, **kwargs),
            *args,
            **kwargs,
        )
    elif isinstance(func, str):
        # Using "getattr" here masks possible AttributeError which we throw
        # in __getattr__, so we should call __getattr__ directly instead.
        agg_func = self.__getattr__(func)
        if callable(agg_func):
            return agg_func(*args, **kwargs)

    result = self._apply_agg_function(
        func,
        *args,
        **kwargs,
    )

    if relabeling_required:
        result = result.iloc[:, order]
        result.columns = new_columns
    return result


# Traceback (AssertionError)
Traceback (most recent call last):
File "../rofl.py", line 18, in <module>
df_equals(md_res, pd_res)
File "/localdisk/dchigare/repos/modin_bp/modin/pandas/test/utils.py", line 527, in df_equals
check_categorical=False,
File "/localdisk/dchigare/miniconda3/envs/modin_tests/lib/python3.7/site-packages/pandas/_testing.py", line 1562, in assert_frame_equal
obj, f"{obj} shape mismatch", f"{repr(left.shape)}", f"{repr(right.shape)}",
File "/localdisk/dchigare/miniconda3/envs/modin_tests/lib/python3.7/site-packages/pandas/_testing.py", line 1036, in raise_assert_detail
raise AssertionError(msg)
AssertionError: DataFrame are different

DataFrame shape mismatch
[left]:  (251, 2)
[right]: (251, 4)

# Fixed code
def aggregate(self, func=None, *args, **kwargs):
    if self._axis != 0:
        # This is not implemented in pandas,
        # so we throw a different message
        raise NotImplementedError("axis other than 0 is not supported")

    if (
        callable(func)
        and isinstance(func, BuiltinFunctionType)
        and func.__name__ in dir(self)
    ):
        func = func.__name__

    relabeling_required = False
    if isinstance(func, dict) or func is None:

        def try_get_str_func(fn):
            if not isinstance(fn, str) and isinstance(fn, Iterable):
                return [try_get_str_func(f) for f in fn]
            return fn.__name__ if callable(fn) and fn.__name__ in dir(self) else fn

        relabeling_required, func_dict, new_columns, order = reconstruct_func(
            func, **kwargs
        )
        func_dict = {col: try_get_str_func(fn) for col, fn in func_dict.items()}

        if any(i not in self._df.columns for i in func_dict.keys()):
            from pandas.core.base import SpecificationError

            raise SpecificationError("nested renamer is not supported")
        if func is None:
            kwargs = {}
        func = func_dict
    elif is_list_like(func):
        return self._default_to_pandas(
            lambda df, *args, **kwargs: df.aggregate(func, *args, **kwargs),
            *args,
            **kwargs,
        )
    elif callable(func):
        return self._apply_agg_function(
            lambda grp, *args, **kwargs: grp.aggregate(func, *args, **kwargs),
            *args,
            **kwargs,
        )
    elif isinstance(func, str):
        # Using "getattr" here masks possible AttributeError which we throw
        # in __getattr__, so we should call __getattr__ directly instead.
        agg_func = self.__getattr__(func)
        if callable(agg_func):
            return agg_func(*args, **kwargs)

    result = self._apply_agg_function(
        func,
        *args,
        **kwargs,
    )

    if relabeling_required:
        if not self._as_index:
            nby_cols = len(result.columns) - len(new_columns)
            order = np.concatenate([np.arange(nby_cols), order + nby_cols])
            by_cols = result.columns[:nby_cols]
            new_columns = pandas.Index(new_columns)
            if by_cols.nlevels != new_columns.nlevels:
                by_cols = by_cols.remove_unused_levels()
                empty_levels = [
                    i
                    for i, level in enumerate(by_cols.levels)
                    if len(level) == 1 and level[0] == ""
                ]
                by_cols = by_cols.droplevel(empty_levels)
            new_columns = by_cols.append(new_columns)
        result = result.iloc[:, order]
        result.columns = new_columns
    return result