Skip to content
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

[BUGFIX] Remove counts when showing a sample #9638

Merged
merged 13 commits into from
Mar 22, 2024
56 changes: 41 additions & 15 deletions great_expectations/render/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,37 @@ def handle_strict_min_max(params: dict) -> tuple[str, str]:
return at_least_str, at_most_str


def _get_value_to_render(value_: Any) -> Any:
if value_ is not None and value_ != "":
return value_
if value_ == "":
return "EMPTY"
return "null"
Comment on lines +244 to +249
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️



def _get_header_row(all_unexpected_in_samples: bool) -> list[str]:
# Check to see if we have *all* of the unexpected values accounted for. If so,
# we show counts. If not then we show Sampled Unexpected Values only.
if all_unexpected_in_samples:
header_row = ["Unexpected Value", "Count"]
else:
header_row = ["Sampled Unexpected Values"]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also remove "Count" from the header (otherwise an empty column would render).

return header_row


def _are_all_unexpected_values_in_samples(
partial_unexpected_counts: list[dict], unexpected_count: int
) -> bool:
total_count: int = 0

for unexpected_count_dict in partial_unexpected_counts:
count: int | None = unexpected_count_dict.get("count")
if count:
total_count += count

return total_count == unexpected_count


def build_count_table(
partial_unexpected_counts: list[dict], unexpected_count: int
) -> tuple[list[str], list[list[Any]]]:
Expand All @@ -257,26 +288,21 @@ def build_count_table(

"""
table_rows: list[list[str | int | None]] = []
total_count: int = 0
all_unexpected_in_samples: bool = _are_all_unexpected_values_in_samples(
partial_unexpected_counts, unexpected_count
)

for unexpected_count_dict in partial_unexpected_counts:
value: Any | None = unexpected_count_dict.get("value")
count: int | None = unexpected_count_dict.get("count")
if count:
total_count += count
if value is not None and value != "":
value = _get_value_to_render(unexpected_count_dict.get("value"))
count = unexpected_count_dict.get("count")
if all_unexpected_in_samples:
table_rows.append([value, count])
elif value == "":
table_rows.append(["EMPTY", count])
else:
table_rows.append(["null", count])
# Since accurate counts for the full dataset are not available,
# we show Sampled Unexpected Values only.
table_rows.append([value])

# Check to see if we have *all* of the unexpected values accounted for. If so,
# we show counts. If not then we show Sampled Unexpected Values
if total_count == unexpected_count:
header_row = ["Unexpected Value", "Count"]
else:
header_row = ["Sampled Unexpected Values", "Count"]
header_row = _get_header_row(all_unexpected_in_samples)
return header_row, table_rows


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -708,29 +708,29 @@
}
},
"table":[
[1, 1],
[2, 1],
[3, 1],
[4, 1],
[5, 1],
[6, 1],
[7, 1],
[8, 1],
[9, 1],
[10, 1],
[11, 1],
[12, 1],
[13, 1],
[14, 1],
[15, 1],
[16, 1],
[17, 1],
[18, 1],
[19, 1],
[20, 1]
[1],
[2],
[3],
[4],
[5],
[6],
[7],
[8],
[9],
[10],
[11],
[12],
[13],
[14],
[15],
[16],
[17],
[18],
[19],
[20]
],
"header_row": [
"Sampled Unexpected Values", "Count"
"Sampled Unexpected Values"
]
}
],
Expand Down Expand Up @@ -1214,68 +1214,68 @@
},
"table": [
[
"Carlsson, Mr Frans Olof", 2
"Carlsson, Mr Frans Olof"
],
[
"Connolly, Miss Kate", 2
"Connolly, Miss Kate"
],
[
"Kelly, Mr James", 2
"Kelly, Mr James"
],
[
"Allen, Miss Elisabeth Walton", 1
"Allen, Miss Elisabeth Walton"
],
[
"Allison, Master Hudson Trevor", 1
"Allison, Master Hudson Trevor"
],
[
"Allison, Miss Helen Loraine", 1
"Allison, Miss Helen Loraine"
],
[
"Allison, Mr Hudson Joshua Creighton", 1
"Allison, Mr Hudson Joshua Creighton"
],
[
"Allison, Mrs Hudson JC (Bessie Waldo Daniels)", 1
"Allison, Mrs Hudson JC (Bessie Waldo Daniels)"
],
[
"Anderson, Mr Harry", 1
"Anderson, Mr Harry"
],
[
"Andrews, Miss Kornelia Theodosia", 1
"Andrews, Miss Kornelia Theodosia"
],
[
"Andrews, Mr Thomas, jr", 1
"Andrews, Mr Thomas, jr"
],
[
"Appleton, Mrs Edward Dale (Charlotte Lamson)", 1
"Appleton, Mrs Edward Dale (Charlotte Lamson)"
],
[
"Artagaveytia, Mr Ramon", 1
"Artagaveytia, Mr Ramon"
],
[
"Astor, Colonel John Jacob", 1
"Astor, Colonel John Jacob"
],
[
"Astor, Mrs John Jacob (Madeleine Talmadge Force)", 1
"Astor, Mrs John Jacob (Madeleine Talmadge Force)"
],
[
"Aubert, Mrs Leontine Pauline", 1
"Aubert, Mrs Leontine Pauline"
],
[
"Barkworth, Mr Algernon H", 1
"Barkworth, Mr Algernon H"
],
[
"Baumann, Mr John D", 1
"Baumann, Mr John D"
],
[
"Baxter, Mr Quigg Edmond", 1
"Baxter, Mr Quigg Edmond"
],
[
"Baxter, Mrs James (Helene DeLaudeniere Chaput)", 1
"Baxter, Mrs James (Helene DeLaudeniere Chaput)"
]
],
"header_row": [
"Sampled Unexpected Values", "Count"
"Sampled Unexpected Values"
]
}
],
Expand Down Expand Up @@ -2367,29 +2367,29 @@
}
},
"table":[
[22.0, 35],
[21.0, 31],
[30.0, 31],
[18.0, 30],
[36.0, 29],
[24.0, 27],
[26.0, 27],
[27.0, 24],
[28.0, 24],
[19.0, 23],
[20.0, 23],
[23.0, 23],
[25.0, 23],
[32.0, 22],
[45.0, 20],
[29.0, 15],
[31.0, 14],
[33.0, 14],
[35.0, 14],
[39.0, 14]
[22.0],
[21.0],
[30.0],
[18.0],
[36.0],
[24.0],
[26.0],
[27.0],
[28.0],
[19.0],
[20.0],
[23.0],
[25.0],
[32.0],
[45.0],
[29.0],
[31.0],
[33.0],
[35.0],
[39.0]
],
"header_row": [
"Sampled Unexpected Values", "Count"
"Sampled Unexpected Values"
]
}
],
Expand Down