Skip to content
Open
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
14 changes: 11 additions & 3 deletions great_expectations/render/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
25 changes: 25 additions & 0 deletions tests/render/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
Loading