| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -593,6 +593,7 @@ def _agg_func(self, func) -> df.DataFrame: | |||
| 593 | 593 | def _agg_dict(self, func: typing.Mapping) -> df.DataFrame: | |
| 594 | 594 | aggregations: typing.List[agg_expressions.Aggregation] = [] | |
| 595 | 595 | column_labels = [] | |
| 596 | + function_labels = [] | ||
| 596 | 597 | ||
| 597 | 598 | want_aggfunc_level = any(utils.is_list_like(aggs) for aggs in func.values()) | |
| 598 | 599 | ||
@@ -602,8 +603,10 @@ def _agg_dict(self, func: typing.Mapping) -> df.DataFrame: | |||
| 602 | 603 | funcs_for_id if utils.is_list_like(funcs_for_id) else [funcs_for_id] | |
| 603 | 604 | ) | |
| 604 | 605 | for f in func_list: | |
| 605 | - aggregations.append(aggs.agg(col_id, agg_ops.lookup_agg_func(f)[0])) | ||
| 606 | + f_op, f_label = agg_ops.lookup_agg_func(f) | ||
| 607 | + aggregations.append(aggs.agg(col_id, f_op)) | ||
| 606 | 608 | column_labels.append(label) | |
| 609 | + function_labels.append(f_label) | ||
| 607 | 610 | agg_block, _ = self._block.aggregate( | |
| 608 | 611 | by_column_ids=self._by_col_ids, | |
| 609 | 612 | aggregations=aggregations, | |
@@ -613,10 +616,7 @@ def _agg_dict(self, func: typing.Mapping) -> df.DataFrame: | |||
| 613 | 616 | agg_block = agg_block.with_column_labels( | |
| 614 | 617 | utils.combine_indices( | |
| 615 | 618 | pd.Index(column_labels), | |
| 616 | - pd.Index( | ||
| 617 | - typing.cast(agg_ops.AggregateOp, agg.op).name | ||
| 618 | - for agg in aggregations | ||
| 619 | - ), | ||
| 619 | + pd.Index(function_labels), | ||
| 620 | 620 | ) | |
| 621 | 621 | ) | |
| 622 | 622 | else: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -717,9 +717,15 @@ def output_type(self, *input_types: dtypes.ExpressionType) -> dtypes.ExpressionT | |||
| 717 | 717 | np.all: all_op, | |
| 718 | 718 | np.any: any_op, | |
| 719 | 719 | np.unique: nunique_op, | |
| 720 | - # TODO(b/443252872): Solve | ||
| 721 | - # list: ArrayAggOp(), | ||
| 722 | 720 | 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, | ||
| 723 | 729 | } | |
| 724 | 730 | ||
| 725 | 731 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6151,6 +6151,28 @@ def test_agg_with_dict_strs(scalars_dfs): | |||
| 6151 | 6151 | ) | |
| 6152 | 6152 | ||
| 6153 | 6153 | ||
| 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 | + | ||
| 6154 | 6176 | def test_agg_with_dict_containing_non_existing_col_raise_key_error(scalars_dfs): | |
| 6155 | 6177 | bf_df, _ = scalars_dfs | |
| 6156 | 6178 | agg_funcs = { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -282,8 +282,6 @@ def test_dataframe_groupby_agg_dict_with_list( | |||
| 282 | 282 | ) | |
| 283 | 283 | bf_result_computed = bf_result.to_pandas() | |
| 284 | 284 | ||
| 285 | - # some inconsistency between versions, so normalize to bigframes behavior | ||
| 286 | - pd_result = pd_result.rename({"amax": "max"}, axis="columns") | ||
| 287 | 285 | pd.testing.assert_frame_equal( | |
| 288 | 286 | pd_result, bf_result_computed, check_dtype=False, check_index_type=False | |
| 289 | 287 | ) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments