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

Skip to content

Commit dbc4295

Browse files
committed
Make eventplot use the standard alias resolution mechanism.
... or rather, prepare its move. Right now eventplot is the sole user of local_over_kwdict for alias resolution. Prepare to move it towards cbook.normalize_kwargs instead. normalize_kwargs is stricter (it raises on conflicting kwargs), so we need a deprecation period for conficting kwargs as well.
1 parent 9984f9c commit dbc4295

File tree

4 files changed

+34
-21
lines changed

4 files changed

+34
-21
lines changed

doc/api/next_api_changes/deprecations.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,12 @@ Revert deprecation \*min, \*max keyword arguments to ``set_x/y/zlim_3d()``
7373
These keyword arguments were deprecated in 3.0, alongside with the respective
7474
parameters in ``set_xlim()`` / ``set_ylim()``. The deprecations of the 2D
7575
versions were already reverted in in 3.1.
76+
77+
``cbook.local_over_kwdict``
78+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
79+
This function is deprecated. Use `.cbook.normalize_kwargs` instead.
80+
81+
Passing both singular and plural *colors*, *linewidths*, *linestyles* to `.Axes.eventplot`
82+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
83+
Passing e.g. both *linewidth* and *linewidths* will raise a TypeError in the
84+
future.

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,9 +1295,9 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
12951295

12961296
# prevent 'singular' keys from **kwargs dict from overriding the effect
12971297
# of 'plural' keyword arguments (e.g. 'color' overriding 'colors')
1298-
colors = cbook.local_over_kwdict(colors, kwargs, 'color')
1299-
linewidths = cbook.local_over_kwdict(linewidths, kwargs, 'linewidth')
1300-
linestyles = cbook.local_over_kwdict(linestyles, kwargs, 'linestyle')
1298+
colors = cbook._local_over_kwdict(colors, kwargs, 'color')
1299+
linewidths = cbook._local_over_kwdict(linewidths, kwargs, 'linewidth')
1300+
linestyles = cbook._local_over_kwdict(linestyles, kwargs, 'linestyle')
13011301

13021302
if not np.iterable(lineoffsets):
13031303
lineoffsets = [lineoffsets]

lib/matplotlib/cbook/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ def __setstate__(self, state):
279279
self.extend(state['seq'])
280280

281281

282+
@deprecated("3.3")
282283
class IgnoredKeywordWarning(UserWarning):
283284
"""
284285
A class for issuing warnings about keyword arguments that will be ignored
@@ -287,6 +288,7 @@ class IgnoredKeywordWarning(UserWarning):
287288
pass
288289

289290

291+
@deprecated("3.3", alternative="normalize_kwargs")
290292
def local_over_kwdict(local_var, kwargs, *keys):
291293
"""
292294
Enforces the priority of a local variable over potentially conflicting
@@ -321,8 +323,12 @@ def local_over_kwdict(local_var, kwargs, *keys):
321323
IgnoredKeywordWarning
322324
For each key in keys that is removed from kwargs but not used as
323325
the output value.
324-
325326
"""
327+
return _local_over_kwdict(local_var, kwargs, *keys, IgnoredKeywordWarning)
328+
329+
330+
def _local_over_kwdict(
331+
local_var, kwargs, *keys, warning_cls=MatplotlibDeprecationWarning):
326332
out = local_var
327333
for key in keys:
328334
kwarg_val = kwargs.pop(key, None)
@@ -331,7 +337,7 @@ def local_over_kwdict(local_var, kwargs, *keys):
331337
out = kwarg_val
332338
else:
333339
_warn_external('"%s" keyword argument will be ignored' % key,
334-
IgnoredKeywordWarning)
340+
warning_cls)
335341
return out
336342

337343

lib/matplotlib/tests/test_axes.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
from numpy.testing import (
2929
assert_allclose, assert_array_equal, assert_array_almost_equal)
3030
from matplotlib import rc_context
31-
from matplotlib.cbook import (
32-
IgnoredKeywordWarning, MatplotlibDeprecationWarning)
31+
from matplotlib.cbook import MatplotlibDeprecationWarning
3332

3433
# Note: Some test cases are run twice: once normally and once with labeled data
3534
# These two must be defined in the same test function or need to have
@@ -3661,7 +3660,7 @@ def test_eventplot_colors(colors):
36613660

36623661

36633662
@image_comparison(['test_eventplot_problem_kwargs.png'], remove_text=True)
3664-
def test_eventplot_problem_kwargs():
3663+
def test_eventplot_problem_kwargs(recwarn):
36653664
'''
36663665
test that 'singular' versions of LineCollection props raise an
36673666
IgnoredKeywordWarning rather than overriding the 'plural' versions (e.g.
@@ -3676,19 +3675,18 @@ def test_eventplot_problem_kwargs():
36763675
fig = plt.figure()
36773676
axobj = fig.add_subplot(111)
36783677

3679-
with warnings.catch_warnings(record=True) as w:
3680-
warnings.simplefilter("always")
3681-
axobj.eventplot(data,
3682-
colors=['r', 'b'],
3683-
color=['c', 'm'],
3684-
linewidths=[2, 1],
3685-
linewidth=[1, 2],
3686-
linestyles=['solid', 'dashed'],
3687-
linestyle=['dashdot', 'dotted'])
3688-
3689-
# check that three IgnoredKeywordWarnings were raised
3690-
assert len(w) == 3
3691-
assert all(issubclass(wi.category, IgnoredKeywordWarning) for wi in w)
3678+
axobj.eventplot(data,
3679+
colors=['r', 'b'],
3680+
color=['c', 'm'],
3681+
linewidths=[2, 1],
3682+
linewidth=[1, 2],
3683+
linestyles=['solid', 'dashed'],
3684+
linestyle=['dashdot', 'dotted'])
3685+
3686+
# check that three IgnoredKeywordWarnings were raised
3687+
assert len(recwarn) == 3
3688+
assert all(issubclass(wi.category, MatplotlibDeprecationWarning)
3689+
for wi in recwarn)
36923690

36933691

36943692
def test_empty_eventplot():

0 commit comments

Comments
 (0)