def METHOD_NAME(self, X):
    name = get_table_name(X)
    group_by_keys = []
    for by_element in self.by if self.by is not None else []:
        expr_to_parse = by_element.expr
        group_by_keys.append(self._get_group_key(expr_to_parse))
    col_not_in_X = np.setdiff1d(group_by_keys, get_columns(X))
    if col_not_in_X.size > 0:
        raise ValueError(
            f"GroupBy key columns {col_not_in_X} not present in input dataframe X."
        )
    if _is_pandas_df(X):
        grouped_df = X.groupby(group_by_keys, sort=False)
    elif _is_spark_df(X):
        X = X.drop(*get_index_names(X))
        grouped_df = X.groupby(group_by_keys)
    else:
        raise ValueError(
            "Only pandas and spark dataframes are supported by the GroupBy operator."
        )
    named_grouped_df = add_table_name(grouped_df, name)
    return named_grouped_df