@@ -938,13 +938,16 @@ def quantile(
938938 9. 'normal_unbiased'
939939
940940 The first three methods are discontinuous.
941- Only 'linear' is implemented for now .
941+ Only 'linear', 'inverted_cdf' and 'averaged_inverted_cdf' are implemented .
942942
943943 keepdims : bool, optional
944944 If this is set to True, the axes which are reduced are left in
945945 the result as dimensions with size one. With this option, the
946946 result will broadcast correctly against the original array `a`.
947947
948+ nan_policy : str, optional
949+ 'propagate' (default) or 'omit'.
950+
948951 weights : array_like, optional
949952 An array of weights associated with the values in `a`. Each value in
950953 `a` contributes to the quantile according to its associated weight.
@@ -1121,20 +1124,24 @@ def quantile(
11211124 msg = "`q` values must be in the range [0, 1]"
11221125 raise ValueError (msg )
11231126
1124- # Delegate where possible.
1127+ # Delegate when possible.
11251128 if is_numpy_namespace (xp ) and nan_policy == "propagate" :
1129+ # TODO: call nanquantile for nan_policy == "omit" once
1130+ # https://github.com/numpy/numpy/issues/29709 is fixed
11261131 return xp .quantile (
11271132 a , q_arr , axis = axis , method = method , keepdims = keepdims , weights = weights
11281133 )
1129- # No delegation for dask: I couldn't make it work
1130- basic_case = method == "linear" and weights is None and nan_policy == "propagate"
1131- if (basic_case and is_jax_namespace (xp )) or is_cupy_namespace (xp ):
1134+ # No delegation for dask: I couldn't make it work.
1135+ basic_case = method == "linear" and weights is None
1136+ jax_or_cupy = is_jax_namespace (xp ) or is_cupy_namespace (xp )
1137+ if basic_case and nan_policy == "propagate" and jax_or_cupy :
11321138 return xp .quantile (a , q_arr , axis = axis , method = method , keepdims = keepdims )
11331139 if basic_case and is_torch_namespace (xp ):
1134- return xp .quantile (a , q_arr , dim = axis , interpolation = method , keepdim = keepdims )
1140+ quantile = xp .quantile if nan_policy == "propagate" else xp .nanquantile
1141+ return quantile (a , q_arr , dim = axis , interpolation = method , keepdim = keepdims )
11351142
1136- # XXX: I'm not sure we want to support dask, it seems uterly slow...
11371143 # Otherwise call our implementation (will sort data)
1144+ # XXX: I'm not sure we want to support dask, it seems uterly slow...
11381145 return _quantile .quantile (
11391146 a ,
11401147 q_arr ,
0 commit comments