feat: Introduce new summary section for data metrics#47
feat: Introduce new summary section for data metrics#47Moritz Potthoff (MoritzPotthoffQC) wants to merge 8 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #47 +/- ##
===========================================
- Coverage 100.00% 99.64% -0.36%
===========================================
Files 14 14
Lines 1052 1117 +65
===========================================
+ Hits 1052 1113 +61
- Misses 0 4 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR extends Diffly’s summary reporting to distinguish change metrics (computed over deltas) from data inspection metrics (describing left/right datasets), and renders the latter in a new dedicated “Data Inspection” section while also separating them in the JSON schema.
Changes:
- Add
Metric.kind("change"vs"data") and mark theNull%preset as a"data"metric. - Split per-column metric outputs into
metricsvsdata_metricsin the summary JSON, and render"data"metrics in a new “Data Inspection” section. - Update summary tests and regenerate pretty-output fixtures to reflect the new section/layout.
Reviewed changes
Copilot reviewed 36 out of 36 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| diffly/metrics/_common.py | Adds Metric.kind to classify metrics by rendering section. |
| diffly/metrics/data.py | Marks Null% preset as a "data" metric. |
| diffly/summary.py | Routes metric labels into change vs data lists; adds “Data Inspection” rendering and JSON schema changes. |
| tests/summary/test_summary.py | Adds coverage for metrics vs data_metrics JSON routing; updates expected JSON shape. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_True_top_True_slim_True_sample_rows_True_sample_pk_True.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_True_top_True_slim_True_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_True_top_True_slim_False_sample_rows_True_sample_pk_True.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_True_top_True_slim_False_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_True_top_False_slim_True_sample_rows_True_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_True_top_False_slim_True_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_True_top_False_slim_False_sample_rows_True_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_True_top_False_slim_False_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_False_top_True_slim_True_sample_rows_True_sample_pk_True.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_False_top_True_slim_True_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_False_top_True_slim_False_sample_rows_True_sample_pk_True.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_False_top_True_slim_False_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_False_top_False_slim_True_sample_rows_True_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_False_top_False_slim_True_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_False_top_False_slim_False_sample_rows_True_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_False_top_False_slim_False_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_True_top_True_slim_True_sample_rows_True_sample_pk_True.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_True_top_True_slim_True_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_True_top_True_slim_False_sample_rows_True_sample_pk_True.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_True_top_True_slim_False_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_True_top_False_slim_True_sample_rows_True_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_True_top_False_slim_True_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_True_top_False_slim_False_sample_rows_True_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_True_top_False_slim_False_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_False_top_True_slim_True_sample_rows_True_sample_pk_True.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_False_top_True_slim_True_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_False_top_True_slim_False_sample_rows_True_sample_pk_True.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_False_top_True_slim_False_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_False_top_False_slim_True_sample_rows_True_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_False_top_False_slim_True_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_False_top_False_slim_False_sample_rows_True_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_False_top_False_slim_False_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
EgeKaraismailogluQC
left a comment
There was a problem hiding this comment.
Thank you Moritz Potthoff (@MoritzPotthoffQC)! In general I am happy with the layout. I added a few comments. In addition to those, I think it would be nice to have at least one summary fixture where we render two or more data metrics rather than just one, just to see what that looks like (maybe I missed it?).
| @@ -716,6 +749,7 @@ class SummaryDataColumn: | |||
| n_total_changes: int | |||
| changes: list[SummaryDataColumnChange] | None | |||
| metrics: dict[str, Any] | None | |||
There was a problem hiding this comment.
?
| metrics: dict[str, Any] | None | |
| change_metrics: dict[str, Any] | None |
| ``kind`` selects the summary section the metric is rendered in: ``"change"`` metrics | ||
| appear as columns in the "Columns" table, while ``"data"`` metrics get their own | ||
| "Data Inspection" section. |
There was a problem hiding this comment.
I think it could be nicer to also explain the semantic difference between change metrics and data metrics. Right now, it sounds like the only difference is where it gets rendered, but the underlying reason for why we present these two options is not clear.
|
|
||
| fn: MetricFn | ||
| selector: cs.Selector | ||
| kind: Literal["change", "data"] = "change" |
There was a problem hiding this comment.
I think it could be good to not provide a default here to force the user to think about what kind of metric they implemented. Wdyt?
There was a problem hiding this comment.
Also, nothing prevents me from "registering" a change metric as a data metric and vice versa. Going a step further, I wish there was a way to infer kind from the type of fn automatically. Right now that does not work of course since both change metrics and data metrics are the same type. Something along these lines:
DataMetricFn = Callable[[pl.Expr], pl.Expr]and then rewrite:
def null_fraction_change(col: pl.Expr) -> pl.Expr:
return col.is_null().mean()
class Metric:
fn: ChangeMetricFn | DataMetricFn
#(property)
def kind(self) -> str:
return "data" if isinstance(DataMetricFn, self.fn) else "change"Metric would then also need to wrap .fn if it is a DataMetricFn to make it have the same interface. Could you follow my idea? Wdyt?
| from ._common import Metric, MetricFn | ||
|
|
||
|
|
||
| def _make_data_metric(fn: MetricFn, selector: cs.Selector = cs.all()) -> Metric: |
There was a problem hiding this comment.
IMO this partial method does not add a lot of value, so it could be dropped. We could just add the kind parameter below in DEFAULT_DATA_METRICS. Wdyt?
Motivation
See this discussion: We want to display
datametrics in their own section in the summary.Changes
Data Inspectionthat gets all the data metrics