-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add per-column metrics to summary #34
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
Open
EgeKaraismailogluQC
wants to merge
23
commits into
main
Choose a base branch
from
numerics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
ae98b68
wip
EgeKaraismailogluQC 31bcd39
wip
EgeKaraismailogluQC db7735f
wip
EgeKaraismailogluQC a1a854e
DAB-1463
EgeKaraismailogluQC d3cc4f1
wip
EgeKaraismailogluQC 8261168
coverage
EgeKaraismailogluQC 584ba71
review
EgeKaraismailogluQC f0e78b7
review
EgeKaraismailogluQC 025d8ff
review
EgeKaraismailogluQC 5f5e0e5
review
EgeKaraismailogluQC 4d79870
review
EgeKaraismailogluQC 266bebd
Update diffly/summary.py
EgeKaraismailogluQC f32f793
review
EgeKaraismailogluQC 8bca8d6
review
EgeKaraismailogluQC 019d914
review
EgeKaraismailogluQC 73bb89f
review
EgeKaraismailogluQC 58645d0
review
EgeKaraismailogluQC 36d9ecb
merge main
EgeKaraismailogluQC 5eb965c
pre-commit
EgeKaraismailogluQC e8aa08a
pre-commit
EgeKaraismailogluQC 139aefa
review OB
EgeKaraismailogluQC 2f9c42c
review OB
EgeKaraismailogluQC de3b484
review OB
EgeKaraismailogluQC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| # Copyright (c) QuantCo 2025-2026 | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Callable | ||
| from dataclasses import dataclass | ||
|
|
||
| import polars as pl | ||
| import polars.selectors as cs | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class _Metric: | ||
| """A metric paired with a column-applicability selector. | ||
|
|
||
| Internal only. | ||
| """ | ||
|
|
||
| fn: Metric | ||
| selector: cs.Selector | ||
|
|
||
|
|
||
| Metric = Callable[[pl.Expr, pl.Expr], pl.Expr] | ||
| """A metric is a callable mapping ``(left_expr, right_expr)`` to a scalar aggregation | ||
| expression. | ||
|
|
||
| The expressions refer to the left-side and right-side values of a single column across | ||
| all joined rows. | ||
| """ | ||
|
|
||
|
|
||
| def _make_numeric_metric(metric: Metric) -> _Metric: | ||
| return _Metric(fn=metric, selector=cs.numeric()) | ||
|
|
||
|
|
||
| def mean(left: pl.Expr, right: pl.Expr) -> pl.Expr: | ||
| """Mean of ``right - left``.""" | ||
| return (right - left).mean() | ||
|
|
||
|
|
||
| def median(left: pl.Expr, right: pl.Expr) -> pl.Expr: | ||
| """Median of ``right - left``.""" | ||
| return (right - left).median() | ||
|
|
||
|
|
||
| def min(left: pl.Expr, right: pl.Expr) -> pl.Expr: | ||
| """Minimum of ``right - left``.""" | ||
| return (right - left).min() | ||
|
|
||
|
|
||
| def max(left: pl.Expr, right: pl.Expr) -> pl.Expr: | ||
| """Maximum of ``right - left``.""" | ||
| return (right - left).max() | ||
|
|
||
|
|
||
| def std(left: pl.Expr, right: pl.Expr) -> pl.Expr: | ||
| """Standard deviation of ``right - left``.""" | ||
| return (right - left).std() | ||
|
|
||
|
|
||
| def mean_absolute_deviation(left: pl.Expr, right: pl.Expr) -> pl.Expr: | ||
| """Mean of ``|right - left|``.""" | ||
| return (right - left).abs().mean() | ||
|
|
||
|
|
||
| def mean_relative_deviation(left: pl.Expr, right: pl.Expr) -> pl.Expr: | ||
| """Mean of ``|(right - left) / left|``. Yields ``inf`` or ``null`` where | ||
| ``left`` is zero.""" | ||
| return ((right - left) / left).abs().mean() | ||
|
|
||
|
|
||
| def quantile(q: float) -> Metric: | ||
| """Factory returning a metric that computes the ``q``-quantile of | ||
| ``right - left``.""" | ||
| if not 0 <= q <= 1: | ||
| raise ValueError(f"q must be in [0, 1], got {q}") | ||
|
|
||
| def _quantile(left: pl.Expr, right: pl.Expr) -> pl.Expr: | ||
| return (right - left).quantile(q) | ||
|
|
||
| return _quantile | ||
|
EgeKaraismailogluQC marked this conversation as resolved.
|
||
|
|
||
|
|
||
| DEFAULT_METRICS: dict[str, Metric] = { | ||
| "Mean": mean, | ||
| "Median": median, | ||
| "Min": min, | ||
| "Max": max, | ||
| "Std": std, | ||
| "Mean absolute deviation": mean_absolute_deviation, | ||
| "Mean relative deviation": mean_relative_deviation, | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is intended. It is a repeatable argument that is used as follows: