Repository navigation
chore: raise minimum Python version to 3.11 - #137
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
wli51
left a comment
There was a problem hiding this comment.
Min python version bump LGTM!
I have a nitpick on the existing suite of pytests. None actually tests the specific EMD output value against a simple EMD problem that has deterministic and analytical solution.
Adding something like:
import polars as pl
import pytest
from buscar.metrics import compute_earth_movers_distance
@pytest.mark.parametrize(
("target", "treated", "expected"),
[
pytest.param(
[[0], [1], [3]],
[[3], [0], [1]],
0.0, # Squared Euclidean: 0.0
id="1d-identical-reordered",
),
pytest.param(
[[0], [0], [2]],
[[0], [2], [2], [2]],
5 / 6, # Squared Euclidean: 5 / 3
id="1d-unequal-sample-sizes",
),
pytest.param(
[[0, 0], [0, 1], [0, 2]],
[[3, 4], [3, 5], [3, 6]],
5.0, # Squared Euclidean: 25.0
id="2d-translation",
),
pytest.param(
[[0, 0], [2, 2], [0, 0], [2, 2]],
[[0, 2], [2, 0], [0, 2], [2, 0]],
2.0, # Squared Euclidean: 4.0
id="2d-same-marginals-different-joint",
),
],
)
def test_compute_earth_movers_distance_matches_analytic_solution(
target, treated, expected
):
"""Check EMD against analytical costs for empirical distributions."""
features = [f"Feature_{i}" for i in range(len(target[0]))]
schema = {feature: pl.Float64 for feature in features}
target_df = pl.DataFrame(target, schema=schema, orient="row")
treated_df = pl.DataFrame(treated, schema=schema, orient="row")
actual = compute_earth_movers_distance(
target_df,
treated_df,
subsample_size=max(len(target), len(treated)),
)
assert actual == pytest.approx(expected, rel=1e-9, abs=1e-12)can help flag potential erratic behavior under various dependency resolution.
|
Thanks @wli51 ! I added in some changes based on what you suggested. Merging this in now. |
Summary
Validation
Summary by CodeRabbit