Skip to content

Revert renaming labels to tick_labels in boxplot_stats() #27916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion galleries/examples/statistics/bxp.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
labels = list('ABCD')

# compute the boxplot stats
stats = cbook.boxplot_stats(data, tick_labels=labels, bootstrap=10000)
stats = cbook.boxplot_stats(data, labels=labels, bootstrap=10000)

# %%
# After we've computed the stats, we can go through and change anything.
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4001,7 +4001,7 @@ def boxplot(self, x, notch=None, sym=None, vert=None, whis=None,
bootstrap = mpl.rcParams['boxplot.bootstrap']

bxpstats = cbook.boxplot_stats(x, whis=whis, bootstrap=bootstrap,
tick_labels=tick_labels, autorange=autorange)
labels=tick_labels, autorange=autorange)
if notch is None:
notch = mpl.rcParams['boxplot.notch']
if vert is None:
Expand Down
20 changes: 7 additions & 13 deletions lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -1126,9 +1126,7 @@ def _broadcast_with_masks(*args, compress=False):
return inputs


@_api.rename_parameter("3.9", "labels", "tick_labels")
def boxplot_stats(X, whis=1.5, bootstrap=None, tick_labels=None,
autorange=False):
def boxplot_stats(X, whis=1.5, bootstrap=None, labels=None, autorange=False):
r"""
Return a list of dictionaries of statistics used to draw a series of box
and whisker plots using `~.Axes.bxp`.
Expand Down Expand Up @@ -1162,14 +1160,10 @@ def boxplot_stats(X, whis=1.5, bootstrap=None, tick_labels=None,
Number of times the confidence intervals around the median
should be bootstrapped (percentile method).

tick_labels : array-like, optional
labels : list of str, optional
Labels for each dataset. Length must be compatible with
dimensions of *X*.

.. versionchanged:: 3.9
Renamed from *labels*, which is deprecated since 3.9
and will be removed in 3.11.

autorange : bool, optional (False)
When `True` and the data are distributed such that the 25th and 75th
percentiles are equal, ``whis`` is set to (0, 100) such that the
Expand Down Expand Up @@ -1245,13 +1239,13 @@ def _compute_conf_interval(data, med, iqr, bootstrap):
X = _reshape_2D(X, "X")

ncols = len(X)
if tick_labels is None:
tick_labels = itertools.repeat(None)
elif len(tick_labels) != ncols:
raise ValueError("Dimensions of tick_labels and X must be compatible")
if labels is None:
labels = itertools.repeat(None)
elif len(labels) != ncols:
raise ValueError("Dimensions of labels and X must be compatible")

input_whis = whis
for ii, (x, label) in enumerate(zip(X, tick_labels)):
for ii, (x, label) in enumerate(zip(X, labels)):

# empty dict
stats = {}
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/cbook.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def boxplot_stats(
X: ArrayLike,
whis: float | tuple[float, float] = ...,
bootstrap: int | None = ...,
tick_labels: ArrayLike | None = ...,
labels: ArrayLike | None = ...,
autorange: bool = ...,
) -> list[dict[str, Any]]: ...

Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/tests/test_cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def test_results_whiskers_percentiles(self):

def test_results_withlabels(self):
labels = ['Test1', 2, 'Aardvark', 4]
results = cbook.boxplot_stats(self.data, tick_labels=labels)
results = cbook.boxplot_stats(self.data, labels=labels)
for lab, res in zip(labels, results):
assert res['label'] == lab

Expand All @@ -158,7 +158,7 @@ def test_results_withlabels(self):
def test_label_error(self):
labels = [1, 2]
with pytest.raises(ValueError):
cbook.boxplot_stats(self.data, tick_labels=labels)
cbook.boxplot_stats(self.data, labels=labels)

def test_bad_dims(self):
data = np.random.normal(size=(34, 34, 34))
Expand Down