Skip to content

fix: groupby aggregates no longer check if grouping keys are numeric #472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bigframes/core/groupby/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ def _convert_index(self, dataframe: df.DataFrame):

def _raise_on_non_numeric(self, op: str):
if not all(
dtype in dtypes.NUMERIC_BIGFRAMES_TYPES_PERMISSIVE
for dtype in self._block.dtypes
self._column_type(col) in dtypes.NUMERIC_BIGFRAMES_TYPES_PERMISSIVE
for col in self._selected_cols
):
raise NotImplementedError(
f"'{op}' does not support non-numeric columns. "
Expand Down
1 change: 1 addition & 0 deletions bigframes/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2337,6 +2337,7 @@ def groupby(
blocks.Label,
bigframes.series.Series,
typing.Sequence[typing.Union[blocks.Label, bigframes.series.Series]],
None,
] = None,
*,
level: typing.Optional[LevelsType] = None,
Expand Down
17 changes: 17 additions & 0 deletions tests/system/small/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,20 @@ def test_series_groupby_agg_list(scalars_df_index, scalars_pandas_df_index):
pd.testing.assert_frame_equal(
pd_result, bf_result_computed, check_dtype=False, check_names=False
)


def test_dataframe_groupby_nonnumeric_with_mean():
df = pd.DataFrame(
{
"key1": ["a", "a", "a", "b"],
"key2": ["a", "a", "c", "c"],
"key3": [1, 2, 3, 4],
"key4": [1.6, 2, 3, 4],
}
)
pd_result = df.groupby(["key1", "key2"]).mean()
bf_result = bpd.DataFrame(df).groupby(["key1", "key2"]).mean().to_pandas()

pd.testing.assert_frame_equal(
pd_result, bf_result, check_index_type=False, check_dtype=False
)