MCPcopy
hub / github.com/dask/dask / quantile

Function quantile

dask/array/reductions.py:1565–1640  ·  view source on GitHub ↗

This works by automatically chunking the reduced axes to a single chunk if necessary and then calling ``numpy.quantile`` function across the remaining dimensions

(
    a,
    q,
    axis=None,
    out=None,
    overwrite_input=False,
    method="linear",
    keepdims=False,
    *,
    weights=None,
    interpolation=None,
)

Source from the content-addressed store, hash-verified

1563
1564@derived_from(np)
1565def quantile(
1566 a,
1567 q,
1568 axis=None,
1569 out=None,
1570 overwrite_input=False,
1571 method="linear",
1572 keepdims=False,
1573 *,
1574 weights=None,
1575 interpolation=None,
1576):
1577 """
1578 This works by automatically chunking the reduced axes to a single chunk if necessary
1579 and then calling ``numpy.quantile`` function across the remaining dimensions
1580 """
1581 if interpolation is not None:
1582 warnings.warn(
1583 "The `interpolation` argument to quantile was renamed to `method`.",
1584 FutureWarning,
1585 stacklevel=2,
1586 )
1587
1588 if method != "linear":
1589 raise TypeError("Cannot pass interpolation and method keywords!")
1590
1591 method = interpolation
1592
1593 if axis is None:
1594 if builtins.any(n_blocks > 1 for n_blocks in a.numblocks):
1595 raise NotImplementedError(
1596 "The da.quantile function only works along an axis. "
1597 "The full algorithm is difficult to do in parallel"
1598 )
1599 axis = tuple(range(len(a.shape)))
1600 elif not isinstance(axis, Iterable):
1601 axis = (axis,)
1602 axis = [ax + a.ndim if ax < 0 else ax for ax in axis]
1603
1604 if overwrite_input:
1605 raise NotImplementedError("da.quantile does not support overwrite_input=True")
1606
1607 # rechunk if reduced axes are not contained in a single chunk
1608 if builtins.any(a.numblocks[ax] > 1 for ax in axis):
1609 a = a.rechunk({ax: -1 if ax in axis else "auto" for ax in range(a.ndim)})
1610
1611 q_arr = asarray_safe(q, like=a)
1612 kwargs = {}
1613 if weights is not None:
1614 if not NUMPY_GE_200:
1615 raise NotImplementedError("da.quantile with weights requires NumPy >=2.0")
1616 kwargs["weights"] = asarray_safe(weights, like=a)
1617
1618 # weights break meta inference (dummy-array shape mismatches weights length).
1619 # There are also issues on NumPy 1.x.
1620 dtype = np.quantile(
1621 np.zeros(1, dtype=a.dtype),
1622 np.asarray(0.5, dtype=q_arr.dtype),

Callers 1

percentileFunction · 0.90

Calls 8

asarray_safeFunction · 0.90
handle_outFunction · 0.90
_get_quantile_chunksFunction · 0.85
anyMethod · 0.45
rechunkMethod · 0.45
quantileMethod · 0.45
zerosMethod · 0.45
map_blocksMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…