MCPcopy Create free account
hub / github.com/dask/dask / test_quantile_weights

Function test_quantile_weights

dask/array/tests/test_reductions.py:1058–1091  ·  view source on GitHub ↗
(np_func, da_func, rechunk, q, keepdims, dask_weights)

Source from the content-addressed store, hash-verified

1056@pytest.mark.parametrize("dask_weights", [True, False])
1057@quantile_nanquantile
1058def test_quantile_weights(np_func, da_func, rechunk, q, keepdims, dask_weights):
1059 shape = 10, 15, 20, 15
1060 chunks = (2, 3, 4, (5 if rechunk else -1))
1061 arr = np.random.randn(*shape)
1062 # 1-D weights whose length matches the reduction axis size
1063 weights = np.random.uniform(0.5, 2.0, size=shape[-1])
1064 if dask_weights:
1065 dweights = da.from_array(weights, chunks=(chunks[-1],))
1066 else:
1067 dweights = weights
1068 # np.nanquantile has a bug with 1-D weights on multi-D arrays
1069 if np_func is np.nanquantile:
1070 weights = np.broadcast_to(weights, arr.shape)
1071
1072 darr = da.from_array(arr, chunks=chunks)
1073
1074 assert_eq(
1075 da_func(
1076 darr,
1077 q,
1078 axis=-1,
1079 weights=dweights,
1080 method="inverted_cdf",
1081 keepdims=keepdims,
1082 ),
1083 np_func(
1084 arr,
1085 q,
1086 axis=-1,
1087 weights=weights,
1088 method="inverted_cdf",
1089 keepdims=keepdims,
1090 ),
1091 )
1092
1093
1094@pytest.mark.skipif(not NUMPY_GE_200, reason="weights requires numpy>=2.0")

Callers

nothing calls this directly

Calls 2

assert_eqFunction · 0.90
uniformMethod · 0.45

Tested by

no test coverage detected