This works by automatically chunking the reduced axes to a single chunk and then calling ``numpy.nanquantile`` function across the remaining dimensions
(
a,
q,
axis=None,
out=None,
overwrite_input=False,
method="linear",
keepdims=False,
*,
weights=None,
interpolation=None,
)
| 1748 | |
| 1749 | @derived_from(np) |
| 1750 | def nanquantile( |
| 1751 | a, |
| 1752 | q, |
| 1753 | axis=None, |
| 1754 | out=None, |
| 1755 | overwrite_input=False, |
| 1756 | method="linear", |
| 1757 | keepdims=False, |
| 1758 | *, |
| 1759 | weights=None, |
| 1760 | interpolation=None, |
| 1761 | ): |
| 1762 | """ |
| 1763 | This works by automatically chunking the reduced axes to a single chunk |
| 1764 | and then calling ``numpy.nanquantile`` function across the remaining dimensions |
| 1765 | """ |
| 1766 | if interpolation is not None: |
| 1767 | warnings.warn( |
| 1768 | "The `interpolation` argument to nanquantile was renamed to `method`.", |
| 1769 | FutureWarning, |
| 1770 | stacklevel=2, |
| 1771 | ) |
| 1772 | |
| 1773 | if method != "linear": |
| 1774 | raise TypeError("Cannot pass interpolation and method keywords!") |
| 1775 | |
| 1776 | method = interpolation |
| 1777 | |
| 1778 | if axis is None: |
| 1779 | if builtins.any(n_blocks > 1 for n_blocks in a.numblocks): |
| 1780 | raise NotImplementedError( |
| 1781 | "The da.nanquantile function only works along an axis. " |
| 1782 | "The full algorithm is difficult to do in parallel" |
| 1783 | ) |
| 1784 | axis = tuple(range(len(a.shape))) |
| 1785 | elif not isinstance(axis, Iterable): |
| 1786 | axis = (axis,) |
| 1787 | axis = [ax + a.ndim if ax < 0 else ax for ax in axis] |
| 1788 | |
| 1789 | if overwrite_input: |
| 1790 | raise NotImplementedError( |
| 1791 | "da.nanquantile does not support overwrite_input=True" |
| 1792 | ) |
| 1793 | |
| 1794 | # rechunk if reduced axes are not contained in a single chunk |
| 1795 | if builtins.any(a.numblocks[ax] > 1 for ax in axis): |
| 1796 | a = a.rechunk({ax: -1 if ax in axis else "auto" for ax in range(a.ndim)}) |
| 1797 | |
| 1798 | q_arr = asarray_safe(q, like=a) |
| 1799 | if ( |
| 1800 | HAS_NUMBAGG |
| 1801 | and (a.dtype.kind in "ui" or a.dtype == np.float64) |
| 1802 | and q_arr.dtype == np.float64 |
| 1803 | and weights is None |
| 1804 | and method == "linear" |
| 1805 | and not keepdims |
| 1806 | and q_arr.ndim <= 1 |
| 1807 | ): |
no test coverage detected
searching dependent graphs…