feat: Support builtins funcs for df.agg (#2256) · googleapis/python-bigquery-dataframes@956a5b0 · GitHub
Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 956a5b0

Browse files
feat: Support builtins funcs for df.agg (#2256)
1 parent 9f497a6 commit 956a5b0

4 files changed

Lines changed: 35 additions & 9 deletions

File tree

bigframes/core/groupby/dataframe_group_by.py

Lines changed: 5 additions & 5 deletions

bigframes/operations/aggregations.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,9 +717,15 @@ def output_type(self, *input_types: dtypes.ExpressionType) -> dtypes.ExpressionT
717717
np.all: all_op,
718718
np.any: any_op,
719719
np.unique: nunique_op,
720-
# TODO(b/443252872): Solve
721-
# list: ArrayAggOp(),
722720
np.size: size_op,
721+
# TODO(b/443252872): Solve
722+
list: ArrayAggOp(),
723+
len: size_op,
724+
sum: sum_op,
725+
min: min_op,
726+
max: max_op,
727+
any: any_op,
728+
all: all_op,
723729
}
724730

725731

tests/system/small/test_dataframe.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6151,6 +6151,28 @@ def test_agg_with_dict_strs(scalars_dfs):
61516151
)
61526152

61536153

6154+
def test_df_agg_with_builtins(scalars_dfs):
6155+
bf_df, pd_df = scalars_dfs
6156+
6157+
bf_result = (
6158+
bf_df[["int64_col", "bool_col"]]
6159+
.dropna()
6160+
.groupby(bf_df.int64_too % 2)
6161+
.agg({"int64_col": [len, sum, min, max, list], "bool_col": [all, any, max]})
6162+
.to_pandas()
6163+
)
6164+
pd_result = (
6165+
pd_df[["int64_col", "bool_col"]]
6166+
.dropna()
6167+
.groupby(pd_df.int64_too % 2)
6168+
.agg({"int64_col": [len, sum, min, max, list], "bool_col": [all, any, max]})
6169+
)
6170+
6171+
pd.testing.assert_frame_equal(
6172+
bf_result, pd_result, check_dtype=False, check_index_type=False
6173+
)
6174+
6175+
61546176
def test_agg_with_dict_containing_non_existing_col_raise_key_error(scalars_dfs):
61556177
bf_df, _ = scalars_dfs
61566178
agg_funcs = {

tests/system/small/test_groupby.py

Lines changed: 0 additions & 2 deletions

0 commit comments

Comments
 (0)