Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix: fix generic error message when entering an incorrect column name #1031

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 7 commits into from
Oct 6, 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
6 changes: 6 additions & 0 deletions 6 bigframes/core/groupby/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ def __getitem__(
keys = list(key)
else:
keys = [key]

bad_keys = [key for key in keys if key not in self._block.column_labels]

if len(bad_keys) > 0:
raise KeyError(f"Columns not found: {str(bad_keys)[1:-1]}")

columns = [
col_id for col_id, label in self._col_id_labels.items() if label in keys
]
Expand Down
28 changes: 28 additions & 0 deletions 28 tests/system/small/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,34 @@ def test_dataframe_groupby_getitem(
pd.testing.assert_series_equal(pd_result, bf_result, check_dtype=False)


def test_dataframe_groupby_getitem_error(
scalars_df_index,
scalars_pandas_df_index,
):
col_names = ["float64_col", "int64_col", "bool_col", "string_col"]
with pytest.raises(KeyError, match="\"Columns not found: 'not_in_group'\""):
arwas11 marked this conversation as resolved.
Show resolved Hide resolved
(
scalars_df_index[col_names]
.groupby("string_col")["not_in_group"]
.min()
.to_pandas()
)


def test_dataframe_groupby_getitem_multiple_columns_error(
scalars_df_index,
scalars_pandas_df_index,
):
col_names = ["float64_col", "int64_col", "bool_col", "string_col"]
with pytest.raises(KeyError, match="\"Columns not found: 'col1', 'col2'\""):
(
scalars_df_index[col_names]
.groupby("string_col")["col1", "col2"]
.min()
.to_pandas()
)


def test_dataframe_groupby_getitem_list(
scalars_df_index,
scalars_pandas_df_index,
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.