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,
)
| 1566 | |
| 1567 | @derived_from(np) |
| 1568 | def quantile( |
| 1569 | a, |
| 1570 | q, |
| 1571 | axis=None, |
| 1572 | out=None, |
| 1573 | overwrite_input=False, |
| 1574 | method="linear", |
| 1575 | keepdims=False, |
| 1576 | *, |
| 1577 | weights=None, |
| 1578 | interpolation=None, |
| 1579 | ): |
| 1580 | """ |
| 1581 | This works by automatically chunking the reduced axes to a single chunk if necessary |
| 1582 | and then calling ``numpy.quantile`` function across the remaining dimensions |
| 1583 | """ |
| 1584 | if interpolation is not None: |
| 1585 | warnings.warn( |
| 1586 | "The `interpolation` argument to quantile was renamed to `method`.", |
| 1587 | FutureWarning, |
| 1588 | stacklevel=2, |
| 1589 | ) |
| 1590 | |
| 1591 | if method != "linear": |
| 1592 | raise TypeError("Cannot pass interpolation and method keywords!") |
| 1593 | |
| 1594 | method = interpolation |
| 1595 | if axis is None: |
| 1596 | if builtins.any(n_blocks > 1 for n_blocks in a.numblocks): |
| 1597 | raise NotImplementedError( |
| 1598 | "The da.quantile function only works along an axis. " |
| 1599 | "The full algorithm is difficult to do in parallel" |
| 1600 | ) |
| 1601 | else: |
| 1602 | axis = tuple(range(len(a.shape))) |
| 1603 | |
| 1604 | if not isinstance(axis, Iterable): |
| 1605 | axis = (axis,) |
| 1606 | |
| 1607 | axis = [ax + a.ndim if ax < 0 else ax for ax in axis] |
| 1608 | |
| 1609 | # rechunk if reduced axes are not contained in a single chunk |
| 1610 | if builtins.any(a.numblocks[ax] > 1 for ax in axis): |
| 1611 | a = a.rechunk({ax: -1 if ax in axis else "auto" for ax in range(a.ndim)}) |
| 1612 | |
| 1613 | if NUMPY_GE_200: |
| 1614 | kwargs = {"weights": weights} |
| 1615 | else: |
| 1616 | kwargs = {} |
| 1617 | |
| 1618 | result = a.map_blocks( |
| 1619 | np.quantile, |
| 1620 | q=q, |
| 1621 | method=method, |
| 1622 | axis=axis, |
| 1623 | keepdims=keepdims, |
| 1624 | drop_axis=axis if not keepdims else None, |
| 1625 | new_axis=0 if isinstance(q, Iterable) else None, |
no test coverage detected