Skip to content

Commit 240eb4f

Browse files
authored
[MAINTENANCE] Include SUMMARY in result_format query support (#11594)
1 parent 9d9687b commit 240eb4f

File tree

3 files changed

+134
-0
lines changed

3 files changed

+134
-0
lines changed

docs/docusaurus/docs/snippets/result_format.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
{"value": "C", "count": 3},
111111
{"value": "D", "count": 2},
112112
],
113+
"unexpected_index_query": "df.filter(items=[3, 4, 5, 6, 7], axis=0)",
113114
}
114115
# </snippet>
115116

great_expectations/expectations/expectation.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3095,6 +3095,9 @@ def _format_map_output( # noqa: C901, PLR0912, PLR0913, PLR0915 # FIXME CoP
30953095
)
30963096

30973097
if result_format["result_format"] == ResultFormat.SUMMARY:
3098+
_add_unexpected_index_query_to_result(
3099+
return_obj, result_format, unexpected_index_query, unexpected_index_column_names
3100+
)
30983101
return return_obj
30993102

31003103
if unexpected_list is not None and not exclude_unexpected_values:

tests/expectations/test_format_map_output.py

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,136 @@ def test_basic_with_return_unexpected_index_query_false_excludes_query(self):
453453
assert "unexpected_index_query" not in result["result"]
454454

455455

456+
class TestSummaryWithReturnUnexpectedIndexQuery:
457+
"""Tests for SUMMARY format with return_unexpected_index_query."""
458+
459+
def test_summary_with_return_unexpected_index_query_includes_query(self):
460+
"""SUMMARY with return_unexpected_index_query=True should include the query."""
461+
result = _format_map_output(
462+
result_format={
463+
"result_format": "SUMMARY",
464+
"return_unexpected_index_query": True,
465+
"partial_unexpected_count": 20,
466+
"include_unexpected_rows": False,
467+
},
468+
success=False,
469+
element_count=5,
470+
nonnull_count=5,
471+
unexpected_count=2,
472+
unexpected_list=["d", "e"],
473+
unexpected_index_list=[1, 2],
474+
unexpected_index_query="SELECT * FROM table WHERE condition",
475+
)
476+
477+
assert result["success"] is False
478+
assert "result" in result
479+
assert result["result"]["unexpected_index_query"] == "SELECT * FROM table WHERE condition"
480+
# SUMMARY should also have standard fields
481+
assert result["result"]["element_count"] == 5
482+
assert result["result"]["unexpected_count"] == 2
483+
# SUMMARY should have partial_unexpected_counts
484+
assert "partial_unexpected_counts" in result["result"]
485+
486+
def test_summary_with_return_unexpected_index_query_includes_column_names(self):
487+
"""SUMMARY with return_unexpected_index_query=True should include column names."""
488+
result = _format_map_output(
489+
result_format={
490+
"result_format": "SUMMARY",
491+
"return_unexpected_index_query": True,
492+
"partial_unexpected_count": 20,
493+
"include_unexpected_rows": False,
494+
},
495+
success=False,
496+
element_count=5,
497+
nonnull_count=5,
498+
unexpected_count=2,
499+
unexpected_list=["d", "e"],
500+
unexpected_index_list=[1, 2],
501+
unexpected_index_query="SELECT pk_1, pk_2 FROM table WHERE condition",
502+
unexpected_index_column_names=["pk_1", "pk_2"],
503+
)
504+
505+
assert result["success"] is False
506+
assert "result" in result
507+
assert (
508+
result["result"]["unexpected_index_query"]
509+
== "SELECT pk_1, pk_2 FROM table WHERE condition"
510+
)
511+
assert result["result"]["unexpected_index_column_names"] == ["pk_1", "pk_2"]
512+
513+
def test_summary_without_return_unexpected_index_query_excludes_query(self):
514+
"""SUMMARY without return_unexpected_index_query should NOT include the query.
515+
516+
This test verifies backwards compatibility.
517+
"""
518+
result = _format_map_output(
519+
result_format={
520+
"result_format": "SUMMARY",
521+
"partial_unexpected_count": 20,
522+
"include_unexpected_rows": False,
523+
},
524+
success=False,
525+
element_count=5,
526+
nonnull_count=5,
527+
unexpected_count=2,
528+
unexpected_list=["d", "e"],
529+
unexpected_index_list=[1, 2],
530+
unexpected_index_query="SELECT * FROM table WHERE condition",
531+
)
532+
533+
assert result["success"] is False
534+
assert "result" in result
535+
assert "unexpected_index_query" not in result["result"]
536+
# But should still have standard SUMMARY fields
537+
assert result["result"]["element_count"] == 5
538+
assert result["result"]["unexpected_count"] == 2
539+
540+
def test_summary_with_return_unexpected_index_query_false_excludes_query(self):
541+
"""SUMMARY with return_unexpected_index_query=False should NOT include the query."""
542+
result = _format_map_output(
543+
result_format={
544+
"result_format": "SUMMARY",
545+
"return_unexpected_index_query": False,
546+
"partial_unexpected_count": 20,
547+
"include_unexpected_rows": False,
548+
},
549+
success=False,
550+
element_count=5,
551+
nonnull_count=5,
552+
unexpected_count=2,
553+
unexpected_list=["d", "e"],
554+
unexpected_index_list=[1, 2],
555+
unexpected_index_query="SELECT * FROM table WHERE condition",
556+
)
557+
558+
assert "unexpected_index_query" not in result["result"]
559+
560+
def test_summary_with_return_unexpected_index_query_but_no_query(self):
561+
"""SUMMARY with return_unexpected_index_query=True but no query.
562+
563+
Should not add unexpected_index_query to the result.
564+
"""
565+
result = _format_map_output(
566+
result_format={
567+
"result_format": "SUMMARY",
568+
"return_unexpected_index_query": True,
569+
"partial_unexpected_count": 20,
570+
"include_unexpected_rows": False,
571+
},
572+
success=True,
573+
element_count=5,
574+
nonnull_count=5,
575+
unexpected_count=0,
576+
unexpected_list=[],
577+
unexpected_index_list=[],
578+
unexpected_index_query=None,
579+
)
580+
581+
assert result["success"] is True
582+
assert "result" in result
583+
assert "unexpected_index_query" not in result["result"]
584+
585+
456586
# Tests for the helper function _add_unexpected_index_query_to_result
457587
class TestAddUnexpectedIndexQueryToResult:
458588
"""Tests for the _add_unexpected_index_query_to_result helper function."""

0 commit comments

Comments
 (0)