8000 Merge pull request #16035 from anntzer/local_over_kwdict · matplotlib/matplotlib@5829e30 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5829e30

Browse files
authored
Merge pull request #16035 from anntzer/local_over_kwdict
Make eventplot use the standard alias resolution mechanism.
2 parents 29a1afe + dbc4295 commit 5829e30

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
@@ -3679,7 +3678,7 @@ def test_eventplot_colors(colors):
36793678

36803679

36813680
@image_comparison(['test_eventplot_problem_kwargs.png'], remove_text=True)
3682-
def test_eventplot_problem_kwargs():
3681+
def test_eventplot_problem_kwargs(recwarn):
36833682
'''
36843683
test that 'singular' versions of LineCollection props raise an
36853684
IgnoredKeywordWarning rather than overriding the 'plural' versions (e.g.
@@ -3694,19 +3693,18 @@ def test_eventplot_problem_kwargs():
36943693
fig = plt.figure()
36953694
axobj = fi 6293 g.add_subplot(111)
36963695

3697-
with warnings.catch_warnings(record=True) as w:
3698-
warnings.simplefilter("always")
3699-
axobj.eventplot(data,
3700-
colors=['r', 'b'],
3701-
color=['c', 'm'],
3702-
linewidths=[2, 1],
3703-
linewidth=[1, 2],
3704-
linestyles=['solid', 'dashed'],
3705-
linestyle=['dashdot', 'dotted'])
3706-
3707-
# check that three IgnoredKeywordWarnings were raised
3708-
assert len(w) == 3
3709-
assert all(issubclass(wi.category, IgnoredKeywordWarning) for wi in w)
3696+
axobj.eventplot(data,
3697+
colors=['r', 'b'],
3698+
color=['c', 'm'],
3699+
linewidths=[2, 1],
3700+
linewidth=[1, 2],
3701+
linestyles=['solid', 'dashed'],
3702+
linestyle=['dashdot', 'dotted'])
3703+
3704+
# check that three IgnoredKeywordWarnings were raised
3705+
assert len(recwarn) == 3
3706+
assert all(issubclass(wi.category, MatplotlibDeprecationWarning)
3707+
for wi in recwarn)
37103708

37113709

37123710
def test_empty_eventplot():

0 commit comments

Comments
 (0)
0