From a91b718a211544b23d54152c2d97aac41d5138ae Mon Sep 17 00:00:00 2001 From: tchalla61 <148000459+Bharath-970@users.noreply.github.com> Date: Fri, 3 Jul 2026 14:41:06 +0530 Subject: [PATCH] [BUGFIX] Fix crash rendering results with unexpected_index_column_names and no domain column _convert_unexpected_indices_to_df computes domain_column_name_list as whatever keys of an unexpected_index_list entry aren't in unexpected_index_column_names. When every key IS an ID/PK column (no separate domain/value column present -- e.g. result_format=COMPLETE with unexpected_index_column_names covering all tracked keys), that list is empty and pandas.DataFrame.groupby([]) raises: ValueError: No group keys passed! aborting Data Docs rendering for the affected result. With no domain column to group by, each unexpected row already stands on its own -- there's nothing to merge across rows. Skip the groupby/agg in that case and wrap each row's values in a single-item list directly, matching the same output shape .groupby().agg() would otherwise produce. Added a regression test exercising the previously-crashing input shape; confirmed as a true guard (fails without the fix, passes with it). Full tests/render/ suite: 168 passed. Closes #11933. --- great_expectations/render/util.py | 14 +++++++++++--- tests/render/test_util.py | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/great_expectations/render/util.py b/great_expectations/render/util.py index 6cdfc23c46ed..36ee5b6f510c 100644 --- a/great_expectations/render/util.py +++ b/great_expectations/render/util.py @@ -445,9 +445,17 @@ def _convert_unexpected_indices_to_df( def _agg_func(y: pd.Series[T]) -> list[T]: # type: ignore[type-var] # not yet supported by pandas-stubs return list(y) - all_unexpected_indices: pd.DataFrame = unexpected_index_df.groupby(domain_column_name_list).agg( - _agg_func - ) + all_unexpected_indices: pd.DataFrame + if domain_column_name_list: + all_unexpected_indices = unexpected_index_df.groupby(domain_column_name_list).agg(_agg_func) + else: + # No domain column is present to group by (every key in each + # `unexpected_index_list` entry is itself one of + # `unexpected_index_column_names`), so there is nothing to aggregate across + # rows -- `.groupby([])` raises `ValueError: No group keys passed!` here. + # Each row already stands on its own; wrap its values in a single-item list + # to match the shape `.groupby().agg(_agg_func)` would otherwise produce. + all_unexpected_indices = unexpected_index_df.map(lambda x: [x]) # 2. add count col_to_count: str = unexpected_index_column_names[0] diff --git a/tests/render/test_util.py b/tests/render/test_util.py index 0214071021b8..42d602fe8571 100644 --- a/tests/render/test_util.py +++ b/tests/render/test_util.py @@ -157,6 +157,31 @@ def test_convert_unexpected_indices_to_df(): assert res.iloc[2].tolist() == ["5", "five", 1] +def test_convert_unexpected_indices_to_df_no_domain_column(): + # Regression test: when every key in each `unexpected_index_list` entry is + # itself one of `unexpected_index_column_names` (i.e. no separate domain/value + # column is present), there is nothing to group by. This previously raised + # `ValueError: No group keys passed!` from `.groupby([])`. See GH#11933. + unexpected_index_list = [{"pk_1": 3}, {"pk_1": 4}, {"pk_1": 5}] + unexpected_index_column_names = ["pk_1"] + + partial_unexpected_counts = [ + {"count": 1, "value": None}, + {"count": 1, "value": None}, + {"count": 1, "value": None}, + ] + + res = _convert_unexpected_indices_to_df( + unexpected_index_list=unexpected_index_list, + unexpected_index_column_names=unexpected_index_column_names, + partial_unexpected_counts=partial_unexpected_counts, + ) + assert list(res) == ["pk_1", "Count"] + assert res.iloc[0].tolist() == ["3", 1] + assert res.iloc[1].tolist() == ["4", 1] + assert res.iloc[2].tolist() == ["5", 1] + + def test_convert_unexpected_indices_to_df_multiple(): result = [ {"animals": "giraffe", "pk_1": 3},