modin/core/dataframe/algebra/default2pandas/groupby.py
def fn(
            df,
            by,
            axis,
            groupby_args,
            map_args,
            numeric_only=True,
            drop=False,
            **kwargs
        ):
            """Group DataFrame and apply aggregation function to each group."""
            if not isinstance(by, (pandas.Series, pandas.DataFrame)):
                by = cls.validate_by(by)
                return agg_func(
                    df.groupby(by=by, axis=axis, **groupby_args), **map_args
                )

            if numeric_only:
                df = df.select_dtypes(include="number")

            if isinstance(by, pandas.DataFrame):
                by = by.squeeze(axis=1)
            if (
                drop
                and isinstance(by, pandas.Series)
                and by.name in df
                and df[by.name].equals(by)
            ):
                by = by.name
            if isinstance(by, pandas.DataFrame):
                df = pandas.concat([df] + [by[[o for o in by if o not in df]]], axis=1)
                by = list(by.columns)

            groupby_args = groupby_args.copy()
            as_index = groupby_args.pop("as_index", True)
            groupby_args["as_index"] = True

            grp = df.groupby(by, axis=axis, **groupby_args)
            result = agg_func(grp, **map_args)

            if isinstance(result, pandas.Series):
                result = result.to_frame()

            if not as_index:
                method = kwargs.get("method")
                if isinstance(by, pandas.Series):
                    # 1. If `drop` is True then 'by' Series represents a column from the
                    #    source frame and so the 'by' is internal.
                    # 2. If method is 'size' then any 'by' is considered to be internal.
                    #    This is a hacky legacy from the ``groupby_size`` implementation:
                    #    https://github.com/modin-project/modin/issues/3739
                    internal_by = (by.name,) if drop or method == "size" else tuple()
                else:
                    internal_by = by

                cls.handle_as_index_for_dataframe(
                    result,
                    internal_by,
                    by_cols_dtypes=(
                        df.index.dtypes.values
                        if isinstance(df.index, pandas.MultiIndex)
                        else (df.index.dtype,)
                    ),
                    by_length=len(by),
                    drop=drop,
                    method=method,
                    inplace=True,
                )

            if result.index.name == "__reduced__":
                result.index.name = None

            return result
Group DataFrame and apply aggregation function to each group.
Group DataFrame and apply aggregation function to each group.
Group DataFrame and apply aggregation function to each group .
def fn(
            df,
            by,
            axis,
            groupby_args,
            map_args,
            numeric_only=True,
            drop=False,
            **kwargs
        ):
            if not isinstance(by, (pandas.Series, pandas.DataFrame)):
                by = cls.validate_by(by)
                return agg_func(
                    df.groupby(by=by, axis=axis, **groupby_args), **map_args
                )
            if numeric_only:
                df = df.select_dtypes(include="number")
            if isinstance(by, pandas.DataFrame):
                by = by.squeeze(axis=1)
            if (
                drop
                and isinstance(by, pandas.Series)
                and by.name in df
                and df[by.name].equals(by)
            ):
                by = by.name
            if isinstance(by, pandas.DataFrame):
                df = pandas.concat([df] + [by[[o for o in by if o not in df]]], axis=1)
                by = list(by.columns)
            groupby_args = groupby_args.copy()
            as_index = groupby_args.pop("as_index", True)
            groupby_args["as_index"] = True
            grp = df.groupby(by, axis=axis, **groupby_args)
            result = agg_func(grp, **map_args)
            if isinstance(result, pandas.Series):
                result = result.to_frame()
            if not as_index:
                method = kwargs.get("method")
                if isinstance(by, pandas.Series):
                    internal_by = (by.name,) if drop or method == "size" else tuple()
                else:
                    internal_by = by
                cls.handle_as_index_for_dataframe(
                    result,
                    internal_by,
                    by_cols_dtypes=(
                        df.index.dtypes.values
                        if isinstance(df.index, pandas.MultiIndex)
                        else (df.index.dtype,)
                    ),
                    by_length=len(by),
                    drop=drop,
                    method=method,
                    inplace=True,
                )
            if result.index.name == "__reduced__":
                result.index.name = None
            return result
def fn ( df , by , axis , groupby_args , map_args , numeric_only = True , drop = False , ** kwargs ) : if not isinstance ( by , ( pandas . Series , pandas . DataFrame ) ) : by = cls . validate_by ( by ) return agg_func ( df . groupby ( by = by , axis = axis , ** groupby_args ) , ** map_args ) if numeric_only : df = df . select_dtypes ( include = "number" ) if isinstance ( by , pandas . DataFrame ) : by = by . squeeze ( axis = 1 ) if ( drop and isinstance ( by , pandas . Series ) and by . name in df and df [ by . name ] . equals ( by ) ) : by = by . name if isinstance ( by , pandas . DataFrame ) : df = pandas . concat ( [ df ] + [ by [ [ o for o in by if o not in df ] ] ] , axis = 1 ) by = list ( by . columns ) groupby_args = groupby_args . copy ( ) as_index = groupby_args . pop ( "as_index" , True ) groupby_args [ "as_index" ] = True grp = df . groupby ( by , axis = axis , ** groupby_args ) result = agg_func ( grp , ** map_args ) if isinstance ( result , pandas . Series ) : result = result . to_frame ( ) if not as_index : method = kwargs . get ( "method" ) if isinstance ( by , pandas . Series ) : internal_by = ( by . name , ) if drop or method == "size" else tuple ( ) else : internal_by = by cls . handle_as_index_for_dataframe ( result , internal_by , by_cols_dtypes = ( df . index . dtypes . values if isinstance ( df . index , pandas . MultiIndex ) else ( df . index . dtype , ) ) , by_length = len ( by ) , drop = drop , method = method , inplace = True , ) if result . index . name == "__reduced__" : result . index . name = None return result
Group DataFrame and apply aggregation function to each group.
Group DataFrame and apply aggregation function to each group .
"""Group DataFrame and apply aggregation function to each group.""" # 1. If `drop` is True then 'by' Series represents a column from the #    source frame and so the 'by' is internal. # 2. If method is 'size' then any 'by' is considered to be internal. #    This is a hacky legacy from the ``groupby_size`` implementation: #    https://github.com/modin-project/modin/issues/3739
df
by
axis
groupby_args
map_args
numeric_only
drop