Skip to content

Commit 5bec466

Browse files
headtr1ckmathause
andauthored
Improve quantile method docstring + error (#6939)
* add comment to setup.cfg that numpy >= 1.22 is recommended * improve docstring and error message for quantile with numpy <1.22 * improve error msg * Add forgotten f string prefix Co-authored-by: Mathias Hauser <mathause@users.noreply.github.com> Co-authored-by: Mathias Hauser <mathause@users.noreply.github.com>
1 parent 756b2a1 commit 5bec466

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ zip_safe = False # https://mypy.readthedocs.io/en/latest/installed_packages.htm
7575
include_package_data = True
7676
python_requires = >=3.8
7777
install_requires =
78-
numpy >= 1.19
78+
numpy >= 1.19 # recommended to use >= 1.22 for full quantile method support
7979
pandas >= 1.2
8080
packaging >= 20.0
8181

xarray/core/dataarray.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3920,19 +3920,20 @@ def quantile(
39203920
8. "median_unbiased" (*)
39213921
9. "normal_unbiased" (*)
39223922
3923-
The first three methods are discontiuous. The following discontinuous
3923+
The first three methods are discontiuous. The following discontinuous
39243924
variations of the default "linear" (7.) option are also available:
39253925
39263926
* "lower"
39273927
* "higher"
39283928
* "midpoint"
39293929
* "nearest"
39303930
3931-
See :py:func:`numpy.quantile` or [1]_ for details. Methods marked with
3932-
an asterix require numpy version 1.22 or newer. The "method" argument was
3933-
previously called "interpolation", renamed in accordance with numpy
3931+
See :py:func:`numpy.quantile` or [1]_ for details. The "method" argument
3932+
was previously called "interpolation", renamed in accordance with numpy
39343933
version 1.22.0.
39353934
3935+
(*) These methods require numpy version 1.22 or newer.
3936+
39363937
keep_attrs : bool or None, optional
39373938
If True, the dataset's attributes (`attrs`) will be copied from
39383939
the original object to the new one. If False (default), the new

xarray/core/dataset.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6738,11 +6738,12 @@ def quantile(
67386738
* "midpoint"
67396739
* "nearest"
67406740
6741-
See :py:func:`numpy.quantile` or [1]_ for a description. Methods marked with
6742-
an asterix require numpy version 1.22 or newer. The "method" argument was
6743-
previously called "interpolation", renamed in accordance with numpy
6741+
See :py:func:`numpy.quantile` or [1]_ for details. The "method" argument
6742+
was previously called "interpolation", renamed in accordance with numpy
67446743
version 1.22.0.
67456744
6745+
(*) These methods require numpy version 1.22 or newer.
6746+
67466747
keep_attrs : bool, optional
67476748
If True, the dataset's attributes (`attrs`) will be copied from
67486749
the original object to the new one. If False (default), the new

xarray/core/variable.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,11 +2066,12 @@ def quantile(
20662066
* "midpoint"
20672067
* "nearest"
20682068
2069-
See :py:func:`numpy.quantile` or [1]_ for details. Methods marked with
2070-
an asterix require numpy version 1.22 or newer. The "method" argument was
2071-
previously called "interpolation", renamed in accordance with numpy
2069+
See :py:func:`numpy.quantile` or [1]_ for details. The "method" argument
2070+
was previously called "interpolation", renamed in accordance with numpy
20722071
version 1.22.0.
20732072
2073+
(*) These methods require numpy version 1.22 or newer.
2074+
20742075
keep_attrs : bool, optional
20752076
If True, the variable's attributes (`attrs`) will be copied from
20762077
the original object to the new one. If False (default), the new
@@ -2141,6 +2142,10 @@ def _wrapper(npa, **kwargs):
21412142
if Version(np.__version__) >= Version("1.22.0"):
21422143
kwargs = {"q": q, "axis": axis, "method": method}
21432144
else:
2145+
if method not in ("linear", "lower", "higher", "midpoint", "nearest"):
2146+
raise ValueError(
2147+
f"Interpolation method '{method}' requires numpy >= 1.22 or is not supported."
2148+
)
21442149
kwargs = {"q": q, "axis": axis, "interpolation": method}
21452150

21462151
result = apply_ufunc(

0 commit comments

Comments
 (0)