Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 376ad69

Browse files
authored
Merge pull request #20327 from seberg/rename-interpolation
BUG,DEP: Fixup quantile/percentile and rename interpolation->method
2 parents b75fe57 + 546c47a commit 376ad69

File tree

8 files changed

+366
-245
lines changed

8 files changed

+366
-245
lines changed
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
Add new linear interpolation methods for ``quantile`` and ``percentile``
2-
------------------------------------------------------------------------
1+
Add new methods for ``quantile`` and ``percentile``
2+
---------------------------------------------------
33

4-
``quantile`` and ``percentile`` now have 13 linear interpolation methods,
5-
nine of which can be found in the scientific literature.
6-
The remaining methods are NumPy specific and are kept for backwards
7-
compatibility. The default is "inclusive" (method 7), whose behavior is equivalent
8-
to the former default "linear".
4+
``quantile`` and ``percentile`` now have have a ``method=``
5+
keyword argument supporting 13 different methods.
6+
This replaces the ``interpolation=`` keyword argument.
7+
8+
The methods are now aligned with nine methods which can be
9+
found in scientific literature and the R language.
10+
The remaining methods are the previous discontinuous variations
11+
of the default "linear" one.
12+
13+
Please see the documentation of `numpy.percentile` for more information.

numpy/core/tests/test_deprecations.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,3 +1230,23 @@ def test_deprecated_module(self):
12301230
def test_deprecated_attr(self):
12311231
finfo = np.finfo(float)
12321232
self.assert_deprecated(lambda: getattr(finfo, "machar"))
1233+
1234+
1235+
class TestQuantileInterpolationDeprecation(_DeprecationTestCase):
1236+
# Deprecated 2021-11-08, NumPy 1.22
1237+
@pytest.mark.parametrize("func",
1238+
[np.percentile, np.quantile, np.nanpercentile, np.nanquantile])
1239+
def test_deprecated(self, func):
1240+
self.assert_deprecated(
1241+
lambda: func([0., 1.], 0., interpolation="linear"))
1242+
self.assert_deprecated(
1243+
lambda: func([0., 1.], 0., interpolation="nearest"))
1244+
1245+
@pytest.mark.parametrize("func",
1246+
[np.percentile, np.quantile, np.nanpercentile, np.nanquantile])
1247+
def test_both_passed(self, func):
1248+
with warnings.catch_warnings():
1249+
# catch the DeprecationWarning so that it does not raise:
1250+
warnings.simplefilter("always", DeprecationWarning)
1251+
with pytest.raises(TypeError):
1252+
func([0., 1.], 0., interpolation="nearest", method="nearest")

0 commit comments

Comments
 (0)