def METHOD_NAME(
    cls, op: DataFrameGroupByAgg, in_data: pd.DataFrame
) -> Union[pd.DataFrame, pd.Series]:
    selections = cls._get_selection_columns(op)
    by_cols = op.raw_groupby_params["by"]
    if by_cols is not None:
        cols = (
            [*selections, *by_cols] if selections is not None else in_data.columns
        )
        res = in_data[cols].drop_duplicates(subset=cols).set_index(by_cols)
    else:  # group by level
        selections = selections if selections is not None else in_data.columns
        level_indexes = cls._get_level_indexes(op, in_data)
        in_data = in_data.reset_index()
        index_names = in_data.columns[level_indexes].tolist()
        cols = [*index_names, *selections]
        res = in_data[cols].drop_duplicates().set_index(index_names)
    # if sort=True is specified， sort index when finishing drop_duplicates.
    if op.raw_groupby_params["sort"]:
        res = res.sort_index()
    if op.output_types[0] == OutputType.series:
        res = res.squeeze()
    return res