From 2d3502b05d91343bd37d8f8074874cfbae9f1e68 Mon Sep 17 00:00:00 2001 From: Michael Waskom Date: Tue, 19 May 2020 15:55:18 -0400 Subject: [PATCH] Deprecate iqr and axlabel; improve deprecation warning class (#2087) * Deprecate iqr and axlabel; improve deprecation warning class * Note deprecations [ci skip] --- doc/releases/v0.11.0.txt | 4 ++++ seaborn/distributions.py | 4 ++-- seaborn/tests/test_utils.py | 15 ++++++++------- seaborn/utils.py | 23 ++++++++++++++++++----- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/doc/releases/v0.11.0.txt b/doc/releases/v0.11.0.txt index 8aff7627dd..7948c51ed9 100644 --- a/doc/releases/v0.11.0.txt +++ b/doc/releases/v0.11.0.txt @@ -27,3 +27,7 @@ v0.11.0 (Unreleased) - Changed how functions that use different representations for numeric and categorical data handle vectors with an `object` data type. Previously, data was considered numeric if it could be coerced to a float representation without error. Now, object-typed vectors are considered numeric only when their contents are themselves numeric. As a consequence, numbers that are encoded as strings will now be treated as categorical data. GH2084 - Improved the error messages produced when categorical plots process the orientation parameter. + +- Deprecated the ``axlabel`` function; use ``ax.set(xlabel=, ylabel=)`` instead. + +- Deprecated the ``iqr`` function; use :func:`scipy.stats.iqr` instead. diff --git a/seaborn/distributions.py b/seaborn/distributions.py index df97d1b7d8..abe0d4f2fc 100644 --- a/seaborn/distributions.py +++ b/seaborn/distributions.py @@ -14,7 +14,7 @@ except ImportError: _has_statsmodels = False -from .utils import iqr, _kde_support, remove_na +from .utils import _kde_support, remove_na from .palettes import color_palette, light_palette, dark_palette, blend_palette from ._decorators import _deprecate_positional_args @@ -28,7 +28,7 @@ def _freedman_diaconis_bins(a): a = np.asarray(a) if len(a) < 2: return 1 - h = 2 * iqr(a) / (len(a) ** (1 / 3)) + h = 2 * stats.iqr(a) / (len(a) ** (1 / 3)) # fall back to sqrt(a) bins if iqr is 0 if h == 0: return int(np.sqrt(a.size)) diff --git a/seaborn/tests/test_utils.py b/seaborn/tests/test_utils.py index 49717a9334..688123293d 100644 --- a/seaborn/tests/test_utils.py +++ b/seaborn/tests/test_utils.py @@ -37,7 +37,7 @@ def test_pmf_hist_basics(): """Test the function to return barplot args for pmf hist.""" - with pytest.warns(UserWarning): + with pytest.warns(FutureWarning): out = utils.pmf_hist(a_norm) assert_equal(len(out), 3) x, h, w = out @@ -45,23 +45,23 @@ def test_pmf_hist_basics(): # Test simple case a = np.arange(10) - with pytest.warns(UserWarning): + with pytest.warns(FutureWarning): x, h, w = utils.pmf_hist(a, 10) nose.tools.assert_true(np.all(h == h[0])) # Test width - with pytest.warns(UserWarning): + with pytest.warns(FutureWarning): x, h, w = utils.pmf_hist(a_norm) assert_equal(x[1] - x[0], w) # Test normalization - with pytest.warns(UserWarning): + with pytest.warns(FutureWarning): x, h, w = utils.pmf_hist(a_norm) nose.tools.assert_almost_equal(sum(h), 1) nose.tools.assert_less_equal(h.max(), 1) # Test bins - with pytest.warns(UserWarning): + with pytest.warns(FutureWarning): x, h, w = utils.pmf_hist(a_norm, 20) assert_equal(len(x), 20) @@ -112,7 +112,7 @@ def test_saturate(): ) def test_sig_stars(p, annot): """Test the sig stars function.""" - with pytest.warns(UserWarning): + with pytest.warns(FutureWarning): stars = utils.sig_stars(p) assert_equal(stars, annot) @@ -120,7 +120,8 @@ def test_sig_stars(p, annot): def test_iqr(): """Test the IQR function.""" a = np.arange(5) - iqr = utils.iqr(a) + with pytest.warns(FutureWarning): + iqr = utils.iqr(a) assert_equal(iqr, 2) diff --git a/seaborn/utils.py b/seaborn/utils.py index 70390a8b84..667ccc3018 100644 --- a/seaborn/utils.py +++ b/seaborn/utils.py @@ -99,7 +99,7 @@ def pmf_hist(a, bins=10): """ msg = "This function is deprecated and will be removed in a future version" - warnings.warn(msg) + warnings.warn(msg, FutureWarning) n, x = np.histogram(a, bins) h = n / n.sum() w = x[1] - x[0] @@ -186,7 +186,13 @@ def set_hls_values(color, h=None, l=None, s=None): # noqa def axlabel(xlabel, ylabel, **kwargs): - """Grab current axis and label it.""" + """Grab current axis and label it. + + DEPRECATED: will be removed in a future version. + + """ + msg = "This function is deprecated and will be removed in a future version" + warnings.warn(msg, FutureWarning) ax = plt.gca() ax.set_xlabel(xlabel, **kwargs) ax.set_ylabel(ylabel, **kwargs) @@ -323,7 +329,7 @@ def percentiles(a, pcts, axis=None): """ msg = "This function is deprecated and will be removed in a future version" - warnings.warn(msg) + warnings.warn(msg, FutureWarning) scores = [] try: @@ -356,7 +362,7 @@ def sig_stars(p): """ msg = "This function is deprecated and will be removed in a future version" - warnings.warn(msg) + warnings.warn(msg, FutureWarning) if p < 0.001: return "***" @@ -370,7 +376,14 @@ def sig_stars(p): def iqr(a): - """Calculate the IQR for an array of numbers.""" + """Calculate the IQR for an array of numbers. + + DEPRECATED: will be removed in a future version. + + """ + msg = "This function is deprecated and will be removed in a future version" + warnings.warn(msg, FutureWarning) + a = np.asarray(a) q1 = stats.scoreatpercentile(a, 25) q3 = stats.scoreatpercentile(a, 75)