Skip to content

Commit 1b48267

Browse files
committed
some more tests
1 parent 8ab7d62 commit 1b48267

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

tests/test_funcs.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,7 @@ def test_against_numpy_nd(
16061606

16071607
@pytest.mark.parametrize("nan_policy", ["no_nans", "propagate"])
16081608
@pytest.mark.parametrize("with_weights", ["with_weights", "no_weights"])
1609-
def test_against_median(
1609+
def test_against_median_min_max(
16101610
self,
16111611
xp: ModuleType,
16121612
nan_policy: str,
@@ -1625,16 +1625,28 @@ def test_against_median(
16251625
# ensure at least one NaN on non-null weight:
16261626
(nz_weights_idx,) = np.where(w_np > 0)
16271627
a_np[nz_weights_idx[0]] = np.nan
1628-
m = "averaged_inverted_cdf"
16291628

1630-
np_median = np.nanmedian if nan_policy == "omit" else np.median
16311629
a_np_med = a_np if w_np is None else a_np[w_np > 0]
1632-
expected = np_median(a_np_med)
16331630
a = xp.asarray(a_np)
16341631
w = xp.asarray(w_np) if w_np is not None else None
1635-
actual = quantile(a, 0.5, method=m, nan_policy=nan_policy, weights=w)
1632+
1633+
np_median = np.nanmedian if nan_policy == "omit" else np.median
1634+
expected = np_median(a_np_med)
1635+
method = "averaged_inverted_cdf"
1636+
actual = quantile(a, 0.5, method=method, nan_policy=nan_policy, weights=w)
16361637
xp_assert_close(actual, xp.asarray(expected))
16371638

1639+
for method in ["inverted_cdf", "averaged_inverted_cdf"]:
1640+
np_min = np.nanmin if nan_policy == "omit" else np.min
1641+
expected = np_min(a_np_med)
1642+
actual = quantile(a, 0., method=method, nan_policy=nan_policy, weights=w)
1643+
xp_assert_close(actual, xp.asarray(expected))
1644+
1645+
np_max = np.nanmax if nan_policy == "omit" else np.max
1646+
expected = np_max(a_np_med)
1647+
actual = quantile(a, 1., method=method, nan_policy=nan_policy, weights=w)
1648+
xp_assert_close(actual, xp.asarray(expected))
1649+
16381650
@pytest.mark.parametrize("keepdims", [True, False])
16391651
@pytest.mark.parametrize("nan_policy", ["no_nans", "propagate", "omit"])
16401652
@pytest.mark.parametrize("q_np", [0.5, 0.0, 1.0, np.linspace(0, 1, num=11)])

0 commit comments

Comments
 (0)