8000 Make eventplot use the standard alias resolution mechanism. · matplotlib/matplotlib@b706f31 · GitHub
[go: up one dir, main page]

Skip to content

Commit b706f31

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 b706f31

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
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: 2 additions & 3 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
@@ -3688,7 +3687,7 @@ def test_eventplot_problem_kwargs():
36883687

36893688
# check that three IgnoredKeywordWarnings were raised
36903689
assert len(w) == 3
3691-
assert all(issubclass(wi.category, IgnoredKeywordWarning) for wi in w)
3690+
assert all(issubclass(wi.category, MatplotlibDeprecationWarning) for wi in w)
36923691

36933692

36943693
def test_empty_eventplot():

0 commit comments

Comments
 (0)
0