Skip to content

Commit

Permalink
Deprecate iqr and axlabel; improve deprecation warning class (#2087)
Browse files Browse the repository at this point in the history
* Deprecate iqr and axlabel; improve deprecation warning class

* Note deprecations

[ci skip]
  • Loading branch information
mwaskom authored May 19, 2020
1 parent 56982f9 commit 2d3502b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
4 changes: 4 additions & 0 deletions doc/releases/v0.11.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 2 additions & 2 deletions seaborn/distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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))
Expand Down
15 changes: 8 additions & 7 deletions seaborn/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,31 @@

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
assert_equal(len(x), len(h))

# 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)

Expand Down Expand Up @@ -112,15 +112,16 @@ 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)


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)


Expand Down
23 changes: 18 additions & 5 deletions seaborn/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 "***"
Expand All @@ -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)
Expand Down

0 comments on commit 2d3502b

Please sign in to comment.