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,
)
| 1548 | |
| 1549 | @derived_from(np) |
| 1550 | def quantile( |
| 1551 | a, |
| 1552 | q, |
| 1553 | axis=None, |
| 1554 | out=None, |
| 1555 | overwrite_input=False, |
| 1556 | method="linear", |
| 1557 | keepdims=False, |
| 1558 | *, |
| 1559 | weights=None, |
| 1560 | interpolation=None, |
| 1561 | ): |
| 1562 | """ |
| 1563 | This works by automatically chunking the reduced axes to a single chunk if necessary |
| 1564 | and then calling ``numpy.quantile`` function across the remaining dimensions |
| 1565 | """ |
| 1566 | if axis is None: |
| 1567 | if builtins.any(n_blocks > 1 for n_blocks in a.numblocks): |
| 1568 | raise NotImplementedError( |
| 1569 | "The da.quantile function only works along an axis. " |
| 1570 | "The full algorithm is difficult to do in parallel" |
| 1571 | ) |
| 1572 | else: |
| 1573 | axis = tuple(range(len(a.shape))) |
| 1574 | |
| 1575 | if not isinstance(axis, Iterable): |
| 1576 | axis = (axis,) |
| 1577 | |
| 1578 | axis = [ax + a.ndim if ax < 0 else ax for ax in axis] |
| 1579 | |
| 1580 | # rechunk if reduced axes are not contained in a single chunk |
| 1581 | if builtins.any(a.numblocks[ax] > 1 for ax in axis): |
| 1582 | a = a.rechunk({ax: -1 if ax in axis else "auto" for ax in range(a.ndim)}) |
| 1583 | |
| 1584 | if NUMPY_GE_200: |
| 1585 | kwargs = {"weights": weights} |
| 1586 | else: |
| 1587 | kwargs = {} |
| 1588 | |
| 1589 | result = a.map_blocks( |
| 1590 | np.quantile, |
| 1591 | q=q, |
| 1592 | method=method, |
| 1593 | interpolation=interpolation, |
| 1594 | axis=axis, |
| 1595 | keepdims=keepdims, |
| 1596 | drop_axis=axis if not keepdims else None, |
| 1597 | new_axis=0 if isinstance(q, Iterable) else None, |
| 1598 | chunks=_get_quantile_chunks(a, q, axis, keepdims), |
| 1599 | **kwargs, |
| 1600 | ) |
| 1601 | |
| 1602 | result = handle_out(out, result) |
| 1603 | return result |
| 1604 | |
| 1605 | |
| 1606 | def _span_indexers(a): |
no test coverage detected