Skip to content

feat: Introduce new summary section for data metrics#47

Open
Moritz Potthoff (MoritzPotthoffQC) wants to merge 24 commits into
mainfrom
data-inspection-section
Open

feat: Introduce new summary section for data metrics#47
Moritz Potthoff (MoritzPotthoffQC) wants to merge 24 commits into
mainfrom
data-inspection-section

Conversation

@MoritzPotthoffQC

@MoritzPotthoffQC Moritz Potthoff (MoritzPotthoffQC) commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Motivation

See this discussion: We want to display data metrics in their own section in the summary.

Changes

  • Add differentiation for the metrics
  • Add new section Data Inspection that gets all the data metrics

@github-actions github-actions Bot added the enhancement New feature or request label Jul 17, 2026
@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.01325% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.64%. Comparing base (01cef28) to head (7ecd908).

Files with missing lines Patch % Lines
diffly/summary.py 97.91% 2 Missing ⚠️
diffly/comparison.py 90.90% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main      #47      +/-   ##
===========================================
- Coverage   100.00%   99.64%   -0.36%     
===========================================
  Files           14       14              
  Lines         1052     1134      +82     
===========================================
+ Hits          1052     1130      +78     
- Misses           0        4       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 the Null% preset as a "data" metric.
  • Split per-column metric outputs into metrics vs data_metrics in 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.

Comment thread diffly/summary.py Outdated

@EgeKaraismailogluQC EgeKaraismailogluQC left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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?).

Comment thread diffly/summary.py Outdated
Comment thread diffly/metrics/_common.py Outdated
Comment thread diffly/metrics/_common.py Outdated

fn: MetricFn
selector: cs.Selector
kind: Literal["change", "data"] = "change"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, thanks for the good point!

I went even a bit further now and clearly split the metrics by introducing two classes ChangeMetric and Data Metric. That way, the diff between them is clear and DataMetric even has a bit more logic. Internally, we now always use these classes (rather then bare callables), because I find it intuitive that way. When running a comparison, the user can still pass in callables. These will be wrapped in the appropriate class, based on the arity of the callable (one expression -> data, two expressions -> change)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

One more change is that we now properly compute data metrics on both columns independently. Previously, we evaluated them on the joined rows (only). Now, we actually compute them on both columns independently. So now we also consider unjoined rows for the data metrics (which is what I expect here).

Comment thread diffly/metrics/data.py Outdated
@MoritzPotthoffQC
Moritz Potthoff (MoritzPotthoffQC) marked this pull request as draft July 22, 2026 17:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 51 out of 52 changed files in this pull request and generated 1 comment.

Comment thread diffly/metrics/__init__.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 84 out of 85 changed files in this pull request and generated 3 comments.

Comment thread diffly/comparison.py
Comment thread diffly/cli.py
Comment thread diffly/metrics/__init__.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@MoritzPotthoffQC

Copy link
Copy Markdown
Contributor Author

EgeKaraismailogluQC I made quite a few changes since your review. I'd appreciate another look. Let me know if you want to chat about this!

@EgeKaraismailogluQC EgeKaraismailogluQC left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for working on this Moritz Potthoff (@MoritzPotthoffQC), looks very nice! Just a few cosmetic comments. Let's also add ! to the PR title to mark it as breaking.

Comment thread diffly/metrics/_common.py
The expressions refer to the left-side and right-side values of a single column across
all joined rows.
"""
ALL_METRICS: dict[str, Metric] = {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

?

Suggested change
ALL_METRICS: dict[str, Metric] = {
DEFAULT_METRICS: dict[str, Metric] = {

Comment thread diffly/metrics/data.py
DEFAULT_DATA_METRICS: dict[str, DataMetric] = {
"Null%": DataMetric(
fn=null_fraction,
selector=cs.all(),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It is the default

Suggested change
selector=cs.all(),

Comment thread diffly/comparison.py


def _resolve_metric(v: ChangeMetricFn | DataMetricFn | Metric) -> Metric:
if isinstance(v, (ChangeMetric, DataMetric)):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

?

Suggested change
if isinstance(v, (ChangeMetric, DataMetric)):
if isinstance(v, Metric):

Comment thread diffly/comparison.py
return v
# Infer the metric family from the callable's arity: a single-argument
# callable describes one side (data), two arguments describe a change.
if len(inspect.signature(v).parameters) >= 2:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why not:

Suggested change
if len(inspect.signature(v).parameters) >= 2:
if isinstance(v, ChangeMetricFn):

Also, how about being a bit defensive here and do:

	elif isinstance(v, DataMetricFn):
		...
	else:
		raise

so that the signature issue is easier to understand for the user?

Comment thread diffly/summary.py
n_total_changes=n_total_changes,
changes=changes,
metrics=metrics_by_column.get(col_name),
change_metrics=change_metrics_by_column.get(col_name) or None,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

?

Suggested change
change_metrics=change_metrics_by_column.get(col_name) or None,
change_metrics=change_metrics_by_column.get(col_name),

Comment thread diffly/summary.py
Comment on lines 1033 to 1052
@@ -963,20 +1041,50 @@ def select_columns(selector: cs.Selector) -> set[str]:
for label, metric in metrics.items()
for column in sorted(metric_to_columns[label])
]
row = joined.select(agg_exprs).collect().row(0, named=True)
for label, columns in metric_to_columns.items():
for column in columns:

row = comp.joined(lazy=True).select(agg_exprs).collect().row(0, named=True)
out: dict[str, dict[str, Any]] = {
c: {} for c in set().union(*metric_to_columns.values())
}
for label in metrics:
for column in metric_to_columns[label]:
out[column][label] = row[f"{label}__{column}"]
return out

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Am I missing something or is this part just a "shallow" refactor?

Comment thread diffly/metrics/data.py
Comment on lines +57 to +58
formatter=lambda value: f"{round(value * 100, 2)}%",
delta_formatter=lambda value: f"{round(value * 100, 2)}",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we use these as the default formatter for DataMetric?

Comment thread diffly/metrics/_common.py

from collections.abc import Callable
from dataclasses import dataclass
Metric = ChangeMetric | DataMetric

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We use ChangeMetricFn | DataMetricFn in a few places. For comfort, how about also defining

MetricFn = ChangeMetricFn | DataMetricFn

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants