Skip to content

Commit a8051a8

Browse files
renames
1 parent ab890eb commit a8051a8

7 files changed

Lines changed: 26 additions & 26 deletions

File tree

diffly/comparison.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
lazy_len,
2626
make_and_validate_mapping,
2727
)
28-
from .metrics import Metric, make_numeric_metric
28+
from .metrics import MetricFn, _make_numeric_metric
2929

3030
if TYPE_CHECKING: # pragma: no cover
3131
# NOTE: We cannot import at runtime as we're otherwise running into circular
@@ -920,7 +920,7 @@ def summary(
920920
right_name: str = Side.RIGHT,
921921
slim: bool = False,
922922
hidden_columns: list[str] | None = None,
923-
metrics: Mapping[str, Metric] | None = None,
923+
metrics: Mapping[str, MetricFn] | None = None,
924924
) -> Summary:
925925
"""Generate a summary of all aspects of the comparison.
926926
@@ -955,7 +955,7 @@ def summary(
955955
:class:`polars.Expr` referring to the left and right values of a single
956956
numerical column across all joined rows, and must return a scalar
957957
aggregation expression. See :doc:`/api/metrics` for the full list of
958-
presets and the :data:`~diffly.metrics.Metric` type. When ``None``
958+
presets and the :data:`~diffly.metrics.MetricFn` type. When ``None``
959959
(default), no metrics are computed; presets are not applied
960960
automatically. Metrics are only computed for numerical columns. Prefer
961961
short labels — the summary has a fixed width and many or long labels
@@ -976,7 +976,7 @@ def summary(
976976
from .summary import Summary
977977

978978
resolved_metrics = (
979-
{label: make_numeric_metric(fn) for label, fn in metrics.items()}
979+
{label: _make_numeric_metric(fn) for label, fn in metrics.items()}
980980
if metrics is not None
981981
else None
982982
)

diffly/metrics.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@
1111

1212

1313
@dataclass(frozen=True)
14-
class _Metric:
15-
"""A metric paired with a column-applicability selector.
14+
class Metric:
15+
"""A metric function paired with a column-applicability selector.
1616
1717
Internal only.
1818
"""
1919

20-
fn: Metric
20+
fn: MetricFn
2121
selector: cs.Selector
2222

2323

24-
Metric = Callable[[pl.Expr, pl.Expr], pl.Expr]
25-
"""A metric is a callable mapping ``(left_expr, right_expr)`` to a scalar aggregation
24+
MetricFn = Callable[[pl.Expr, pl.Expr], pl.Expr]
25+
"""A metric function maps ``(left_expr, right_expr)`` to a scalar aggregation
2626
expression.
2727
2828
The expressions refer to the left-side and right-side values of a single column across
2929
all joined rows.
3030
"""
3131

3232

33-
def _make_numeric_metric(metric: Metric) -> _Metric:
34-
return _Metric(fn=metric, selector=cs.numeric())
33+
def _make_numeric_metric(fn: MetricFn) -> Metric:
34+
return Metric(fn=fn, selector=cs.numeric())
3535

3636

3737
def mean(left: pl.Expr, right: pl.Expr) -> pl.Expr:
@@ -70,7 +70,7 @@ def mean_relative_deviation(left: pl.Expr, right: pl.Expr) -> pl.Expr:
7070
return ((right - left) / left).abs().mean()
7171

7272

73-
def quantile(q: float) -> Metric:
73+
def quantile(q: float) -> MetricFn:
7474
"""Factory returning a metric that computes the ``q``-quantile of
7575
``right - left``."""
7676
if not 0 <= q <= 1:
@@ -82,7 +82,7 @@ def _quantile(left: pl.Expr, right: pl.Expr) -> pl.Expr:
8282
return _quantile
8383

8484

85-
DEFAULT_METRICS: dict[str, Metric] = {
85+
DEFAULT_METRICS: dict[str, MetricFn] = {
8686
"Mean": mean,
8787
"Median": median,
8888
"Min": min,

diffly/summary.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from rich.text import Text
2424

2525
from ._utils import Side, capitalize_first
26-
from .metrics import _Metric
26+
from .metrics import Metric
2727

2828
if TYPE_CHECKING: # pragma: no cover
2929
from .comparison import DataFrameComparison
@@ -61,7 +61,7 @@ def __init__(
6161
right_name: str,
6262
slim: bool,
6363
hidden_columns: list[str] | None,
64-
metrics: Mapping[str, _Metric] | None,
64+
metrics: Mapping[str, Metric] | None,
6565
):
6666
self.slim = slim
6767
self._data = _compute_summary_data(
@@ -772,7 +772,7 @@ def _compute_summary_data(
772772
right_name: str,
773773
slim: bool,
774774
hidden_columns: list[str] | None,
775-
metrics: Mapping[str, _Metric] | None,
775+
metrics: Mapping[str, Metric] | None,
776776
) -> SummaryData:
777777
from .comparison import DataFrameComparison
778778

@@ -839,7 +839,7 @@ def _validate_primary_key_hidden_columns() -> None:
839839
_metric_labels=[],
840840
)
841841

842-
metrics_resolved: dict[str, _Metric] = dict(metrics or {})
842+
metrics_resolved: dict[str, Metric] = dict(metrics or {})
843843
metrics_by_column = _compute_column_metrics(comp, metrics_resolved)
844844
metric_labels = list(metrics_resolved.keys())
845845

@@ -935,7 +935,7 @@ def _compute_rows(comp: DataFrameComparison, slim: bool) -> SummaryDataRows | No
935935

936936
def _compute_column_metrics(
937937
comp: DataFrameComparison,
938-
metrics: Mapping[str, _Metric],
938+
metrics: Mapping[str, Metric],
939939
) -> dict[str, dict[str, Any]]:
940940
if comp.primary_key is None or comp.num_rows_joined() == 0:
941941
return {}

diffly/testing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from ._compat import dy
2121
from .comparison import DataFrameComparison, compare_frames
22-
from .metrics import Metric
22+
from .metrics import MetricFn
2323

2424

2525
def assert_collection_equal(
@@ -40,7 +40,7 @@ def assert_collection_equal(
4040
right_name: str = Side.RIGHT,
4141
slim: bool = False,
4242
hidden_columns: list[str] | None = None,
43-
metrics: Mapping[str, Metric] | None = None,
43+
metrics: Mapping[str, MetricFn] | None = None,
4444
) -> None:
4545
"""Assert that two :mod:`dataframely` collections are equal.
4646
@@ -174,7 +174,7 @@ def assert_frame_equal(
174174
right_name: str = Side.RIGHT,
175175
slim: bool = False,
176176
hidden_columns: list[str] | None = None,
177-
metrics: Mapping[str, Metric] | None = None,
177+
metrics: Mapping[str, MetricFn] | None = None,
178178
) -> None:
179179
"""Assert that two :mod:`polars` data frames are equal.
180180

docs/api/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ API Reference
2727
:link: metrics
2828
:link-type: doc
2929

30-
Built-in metric presets and the ``Metric`` callable for ``summary(metrics=...)``.
30+
Built-in metric presets and the ``MetricFn`` callable for ``summary(metrics=...)``.
3131

3232
.. grid-item-card:: Testing
3333
:link: testing

docs/api/metrics.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ Metrics
66

77
Metrics are scalar aggregations computed per numerical column when generating a
88
:meth:`~diffly.comparison.DataFrameComparison.summary`. Pass them via the
9-
``metrics`` argument as a mapping from display label to a :data:`Metric`
9+
``metrics`` argument as a mapping from display label to a :data:`MetricFn`
1010
callable. :mod:`diffly.metrics` ships a set of presets; you can also supply
1111
your own callable ``(left_expr, right_expr) -> pl.Expr``.
1212

13-
.. autodata:: Metric
13+
.. autodata:: MetricFn
1414
:no-value:
1515

1616
Presets

tests/test_metrics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pytest
88

99
from diffly import metrics
10-
from diffly.metrics import Metric
10+
from diffly.metrics import MetricFn
1111

1212

1313
@pytest.fixture
@@ -16,7 +16,7 @@ def frame() -> pl.DataFrame:
1616
return pl.DataFrame({"l": [1, 2, 3, None], "r": [1, 2, 5, 4]})
1717

1818

19-
def _apply(metric: Metric, frame: pl.DataFrame) -> float:
19+
def _apply(metric: MetricFn, frame: pl.DataFrame) -> float:
2020
return frame.select(metric(pl.col("l"), pl.col("r"))).item()
2121

2222

0 commit comments

Comments
 (0)