From c560fd0f1cee86aa96b611931c737d49324d048d Mon Sep 17 00:00:00 2001 From: lsabor Date: Thu, 29 Aug 2024 07:21:51 -0700 Subject: [PATCH] add multi-percentile test --- tests/test_utils/test_measures.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/test_utils/test_measures.py b/tests/test_utils/test_measures.py index c9edb6adff..5100775be6 100644 --- a/tests/test_utils/test_measures.py +++ b/tests/test_utils/test_measures.py @@ -5,12 +5,13 @@ @pytest.mark.parametrize( - "values, weights, percentile, expected_result", + "values, weights, percentiles, expected_result", [ - ([[0.5, 0.5], [0.6, 0.4]], None, 50.0, [[0.55, 0.45]]), - ([[0.5, 0.5], [0.6, 0.4]], None, 40.0, [[0.5, 0.4]]), - ([[0.3, 0.7], [0.6, 0.4], [0.1, 0.9]], None, 50.0, [[0.3, 0.7]]), - ([[0.5, 0.5], [0.6, 0.4], [0.1, 0.9]], [0.1, 0.1, 1.0], 50.0, [[0.1, 0.9]]), + ([[0.5, 0.5], [0.6, 0.4]], None, [50.0], [[0.55, 0.45]]), + ([[0.5, 0.5], [0.6, 0.4]], None, [40.0], [[0.5, 0.4]]), + ([[0.5, 0.5], [0.6, 0.4]], None, [50.0, 40.0], [[0.55, 0.45], [0.5, 0.4]]), + ([[0.3, 0.7], [0.6, 0.4], [0.1, 0.9]], None, [50.0], [[0.3, 0.7]]), + ([[0.5, 0.5], [0.6, 0.4], [0.1, 0.9]], [0.1, 0.1, 1.0], [50.0], [[0.1, 0.9]]), ( [ [0.33, 0.33, 0.34], @@ -18,7 +19,7 @@ [0.4, 0.2, 0.4], ], None, - 50.0, + [50.0], [[0.33, 0.33, 0.4]], # Does not sum to 1, and that's okay ), ( @@ -28,7 +29,7 @@ [0.0, 0.0, 1.0], ], None, - 50.0, + [50.0], [[0.0, 0.0, 0.0]], ), ( @@ -39,7 +40,7 @@ [0.2, 0.6, 0.2], ], None, - 50.0, + [50.0], [[0.265, 0.415, 0.37]], ), ( @@ -50,19 +51,19 @@ [0.2, 0.6, 0.2], ], [0.1, 0.2, 0.3, 0.4], - 50.0, + [50.0], [[0.2, 0.5, 0.37]], ), ], ) -def test_weighted_percentile_2d(values, weights, percentile, expected_result): +def test_weighted_percentile_2d(values, weights, percentiles, expected_result): values = np.array(values) weights = np.array(weights) if weights is not None else None result = weighted_percentile_2d( - values=values, weights=weights, percentiles=[percentile] + values=values, weights=weights, percentiles=percentiles ) np.testing.assert_allclose(result, expected_result) - if weights is None and percentile == 50.0: # should behave like np.median + if weights is None and [percentiles] == [50.0]: # should behave like np.median numpy_medians = np.median(values, axis=0) np.testing.assert_allclose(result, [numpy_medians])