8000 Move from cbook._warn_deprecated() to _api.warn_deprecated() · matplotlib/matplotlib@1c9c162 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1c9c162

Browse files
committed
Move from cbook._warn_deprecated() to _api.warn_deprecated()
1 parent d53555b commit 1c9c162

37 files changed

+154
-161
lines changed

lib/matplotlib/_constrained_layout.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import numpy as np
1919

20-
import matplotlib.cbook as cbook
20+
from matplotlib import _api
2121
import matplotlib.transforms as mtransforms
2222

2323
_log = logging.getLogger(__name__)
@@ -94,9 +94,9 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
9494
gss.add(gs)
9595
gss = list(gss)
9696
if len(gss) == 0:
97-
cbook._warn_external('There are no gridspecs with layoutgrids. '
98-
'Possibly did not call parent GridSpec with the'
99-
' "figure" keyword')
97+
_api.warn_external('There are no gridspecs with layoutgrids. '
98+
'Possibly did not call parent GridSpec with the'
99+
' "figure" keyword')
100100

101101
for _ in range(2):
102102
# do the algorithm twice. This has to be done because decorations
@@ -122,9 +122,9 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
122122
_reposition_axes(fig, renderer, h_pad=h_pad, w_pad=w_pad,
123123
hspace=hspace, wspace=wspace)
124124
else:
125-
cbook._warn_external('constrained_layout not applied because '
126-
'axes sizes collapsed to zero. Try making '
127-
'figure larger or axes decorations smaller.')
125+
_api.warn_external('constrained_layout not applied because '
126+
'axes sizes collapsed to zero. Try making '
127+
'figure larger or axes decorations smaller.')
128128
_reset_margins(fig)
129129

130130

lib/matplotlib/animation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ def frame_format(self, frame_format):
475475
if frame_format in self.supported_formats:
476476
self._frame_format = frame_format
477477
else:
478-
cbook._warn_external(
478+
_api.warn_external(
479479
f"Ignoring file format {frame_format!r} which is not "
480480
f"supported by {type(self).__name__}; using "
481481
f"{self.supported_formats[0]} instead.")

lib/matplotlib/artist.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -901,8 +901,7 @@ def set_rasterized(self, rasterized):
901901
rasterized : bool
902902
"""
903903
if rasterized and not hasattr(self.draw, "_supports_rasterization"):
904-
cbook._warn_external(
905-
"Rasterization of '%s' will be ignored" % self)
904+
_api.warn_external("Rasterization of '{self}' will be ignored")
906905

907906
self._rasterized = rasterized
908907

lib/matplotlib/axes/_axes.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4722,9 +4722,8 @@ def reduce_C_function(C: array) -> float
47224722
# Set normalizer if bins is 'log'
47234723
if bins == 'log':
47244724
if norm is not None:
4725-
cbook._warn_external("Only one of 'bins' and 'norm' "
4726-
"arguments can be supplied, ignoring "
4727-
"bins={}".format(bins))
4725+
_api.warn_external("Only one of 'bins' and 'norm' arguments "
4726+
f"can be supplied, ignoring bins={bins}")
47284727
else:
47294728
norm = mcolors.LogNorm()
47304729
bins = None
@@ -5436,9 +5435,9 @@ def _pcolorargs(self, funcname, *args, shading='flat', **kwargs):
54365435
try:
54375436
_api.check_in_list(_valid_shading, shading=shading)
54385437
except ValueError as err:
5439-
cbook._warn_external(f"shading value '{shading}' not in list of "
5440-
f"valid values {_valid_shading}. Setting "
5441-
"shading='auto'.")
5438+
_api.warn_external(f"shading value '{shading}' not in list of "
5439+
f"valid values {_valid_shading}. Setting "
5440+
"shading='auto'.")
54425441
shading = 'auto'
54435442

54445443
if len(args) == 1:
@@ -5523,7 +5522,7 @@ def _interp_grid(X):
55235522
if np.shape(X)[1] > 1:
55245523
dX = np.diff(X, axis=1)/2.
55255524
if not (np.all(dX >= 0) or np.all(dX <= 0)):
5526-
cbook._warn_external(
5525+
_api.warn_external(
55275526
f"The input coordinates to {funcname} are "
55285527
"interpreted as cell centers, but are not "
55295528
"monotonically increasing or decreasing. "

lib/matplotlib/axes/_base.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def __call__(self, *args, data=None, **kwargs):
268268
label_namer_idx = 1
269269
else:
270270
if replaced[1] is not args[1]: # case 2a)
271-
cbook._warn_external(
271+
_api.warn_external(
272272
f"Second argument {args[1]!r} is ambiguous: could "
273273
f"be a format string but is in 'data'; using as "
274274
f"data. If it was intended as data, set the "
@@ -2456,7 +2456,7 @@ def margins(self, *margins, x=None, y=None, tight=True):
24562456

24572457
if x is None and y is None:
24582458
if tight is not True:
2459-
cbook._warn_external(f'ignoring tight={tight!r} in get mode')
2459+
_api.warn_external(f'ignoring tight={tight!r} in get mode')
24602460
return self._xmargin, self._ymargin
24612461

24622462
if tight is not None:
@@ -3442,19 +3442,19 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False,
34423442
# so only grab the limits if we really need them.
34433443
old_left, old_right = self.get_xlim()
34443444
if left <= 0:
3445-
cbook._warn_external(
3445+
_api.warn_external(
34463446
'Attempted to set non-positive left xlim on a '
34473447
'log-scaled axis.\n'
34483448
'Invalid limit will be ignored.')
34493449
left = old_left
34503450
if right <= 0:
3451-
cbook._warn_external(
3451+
_api.warn_external(
34523452
'Attempted to set non-positive right xlim on a '
34533453
'log-scaled axis.\n'
34543454
'Invalid limit will be ignored.')
34553455
right = old_right
34563456
if left == right:
3457-
cbook._warn_external(
3457+
_api.warn_external(
34583458
f"Attempting to set identical left == right == {left} results "
34593459
f"in singular transformations; automatically expanding.")
34603460
reverse = left > right
@@ -3768,19 +3768,19 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
37683768
# so only grab the limits if we really need them.
37693769
old_bottom, old_top = self.get_ylim()
37703770
if bottom <= 0:
3771-
cbook._warn_external(
3771+
_api.warn_external(
37723772
'Attempted to set non-positive bottom ylim on a '
37733773
'log-scaled axis.\n'
37743774
'Invalid limit will be ignored.')
37753775
bottom = old_bottom
37763776
if top <= 0:
3777-
cbook._warn_external(
3777+
_api.warn_external(
37783778
'Attempted to set non-positive top ylim on a '
37793779
'log-scaled axis.\n'
37803780
'Invalid limit will be ignored.')
37813781
top = old_top
37823782
if bottom == top:
3783-
cbook._warn_external(
3783+
_api.warn_external(
37843784
f"Attempting to set identical bottom == top == {bottom} "
37853785
f"results in singular transformations; automatically "
37863786
f"expanding.")
@@ -4067,7 +4067,7 @@ def _set_view_from_bbox(self, bbox, direction='in',
40674067
xzc + xwidth/2./scl, yzc + ywidth/2./scl]
40684068
elif len(bbox) != 4:
40694069
# should be len 3 or 4 but nothing else
4070-
cbook._warn_external(
4070+
_api.warn_external(
40714071
"Warning in _set_view_from_bbox: bounding box is not a tuple "
40724072
"of length 3 or 4. Ignoring the view change.")
40734073
return
@@ -4211,7 +4211,7 @@ def format_deltas(key, dx, dy):
42114211
result = (mtransforms.Bbox(newpoints)
42124212
.transformed(p.trans_inverse))
42134213
except OverflowError:
4214-
cbook._warn_external('Overflow while panning')
4214+
_api.warn_external('Overflow while panning')
42154215
return
42164216
else:
42174217
return

lib/matplotlib/axes/_secondary_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def set_aspect(self, *args, **kwargs):
246246
Secondary axes cannot set the aspect ratio, so calling this just
247247
sets a warning.
248248
"""
249-
cbook._warn_external("Secondary axes can't set the aspect ratio")
249+
_api.warn_external("Secondary axes can't set the aspect ratio")
250250

251251
def set_color(self, color):
252252
"""

lib/matplotlib/axis.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,9 +1390,9 @@ def grid(self, b=None, which='major', **kwargs):
13901390
raise ValueError(
13911391
"'b' and 'visible' specify inconsistent grid visibilities")
13921392
if kwargs and not b: # something false-like but not None
1393-
cbook._warn_external('First parameter to grid() is false, '
1394-
'but line properties are supplied. The '
1395-
'grid will be enabled.')
1393+
_api.warn_external('First parameter to grid() is false, '
1394+
'but line properties are supplied. The '
1395+
'grid will be enabled.')
13961396
b = True
13971397
which = which.lower()
13981398
_api.check_in_list(['major', 'minor', 'both'], which=which)
@@ -1604,8 +1604,8 @@ def _set_formatter(self, formatter, level):
16041604
if (isinstance(formatter, mticker.FixedFormatter)
16051605
and len(formatter.seq) > 0
16061606
and not isinstance(level.locator, mticker.FixedLocator)):
1607-
cbook._warn_external('FixedFormatter should only be used together '
1608-
'with FixedLocator')
1607+
_api.warn_external('FixedFormatter should only be used together '
1608+
'with FixedLocator')
16091609

16101610
if level == self.major:
16111611
self.isDefault_majfmt = False

lib/matplotlib/backend_bases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3546,7 +3546,7 @@ def show(cls, *, block=None):
35463546
try:
35473547
manager.show() # Emits a warning for non-interactive backend.
35483548
except NonGuiException as exc:
3549-
cbook._warn_external(str(exc))
3549+
_api.warn_external(str(exc))
35503550
if cls.mainloop is None:
35513551
return
35523552
if block is None:

lib/matplotlib/backend_managers.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ def update_keymap(self, name, key, *args):
209209
key = [key]
210210
for k in key:
211211
if k in self._keys:
212-
cbook._warn_external('Key %s changed from %s to %s' %
213-
(k, self._keys[k], name))
212+
_api.warn_external(
213+
f'Key {k} changed from {self._keys[k]} to {name}')
214214
self._keys[k] = name
215215

216216
def remove_tool(self, name):
@@ -267,8 +267,8 @@ def add_tool(self, name, tool, *args, **kwargs):
267267
raise ValueError('Impossible to find class for %s' % str(tool))
268268

269269
if name in self._tools:
270-
cbook._warn_external('A "Tool class" with the same name already '
271-
'exists, not added')
270+
_api.warn_external('A "Tool class" with the same name already '
271+
'exists, not added')
272272
return self._tools[name]
273273

274274
tool_obj = tool_cls(self, name, *args, **kwargs)
@@ -437,7 +437,6 @@ def get_tool(self, name, warn=True):
437437
return name
438438
if name not in self._tools:
439439
if warn:
440-
cbook._warn_external("ToolManager does not control tool "
441-
"%s" % name)
440+
_api.warn_external("ToolManager does not control tool {name}")
442441
return None
443442
return self._tools[name]

lib/matplotlib/backend_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class ToolBase:
8080
"""
8181

8282
def __init__(self, toolmanager, name):
83-
cbook._warn_external(
83+
_api.warn_external(
8484
'The new Tool classes introduced in v1.5 are experimental; their '
8585
'API (including names) will likely change in future versions.')
8686
self._name = name

lib/matplotlib/backends/backend_pdf.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,12 @@ def check_trapped(x):
210210
}
211211
for k in info:
212212
if k not in keywords:
213-
cbook._warn_external(f'Unknown infodict keyword: {k!r}. '
214-
f'Must be one of {set(keywords)!r}.')
213+
_api.warn_external(f'Unknown infodict keyword: {k!r}. '
214+
f'Must be one of {set(keywords)!r}.')
215215
elif not keywords[k](info[k]):
216-
cbook._warn_external(f'Bad value for infodict keyword {k}. '
217-
f'Got {info[k]!r} which is not '
218-
f'{keywords[k].text_for_warning}.')
216+
_api.warn_external(f'Bad value for infodict keyword {k}. '
217+
f'Got {info[k]!r} which is not '
218+
f'{keywords[k].text_for_warning}.')
219219
if 'Trapped' in info:
220220
info['Trapped'] = Name(info['Trapped'])
221221

lib/matplotlib/backends/backend_pgf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ def draw_image(self, gc, x, y, im, transform=None):
628628
return
629629

630630
if not os.path.exists(getattr(self.fh, "name", "")):
631-
cbook._warn_external(
631+
_api.warn_external(
632632
"streamed pgf-code does not support raster graphics, consider "
633633
"using the pgf-to-pdf option.")
634634

lib/matplotlib/backends/qt_editor/_formlayout.py

Lines changed: 2 additions & 2 deletions
48DA
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import logging
4747
from numbers import Integral, Real
4848

49-
from matplotlib import cbook, colors as mcolors
49+
from matplotlib import _api, colors as mcolors
5050
from matplotlib.backends.qt_compat import QtGui, QtWidgets, QtCore
5151

5252
_log = logging.getLogger(__name__)
@@ -95,7 +95,7 @@ def to_qcolor(color):
9595
try:
9696
rgba = mcolors.to_rgba(color)
9797
except ValueError:
98-
cbook._warn_external('Ignoring invalid color %r' % color)
98+
_api.warn_external(f'Ignoring invalid color {color!r}')
9999
return qcolor # return invalid QColor
100100
qcolor.setRgbF(*rgba)
101101
return qcolor

lib/matplotlib/bezier.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ def get_parallels(bezier2, width):
478478
cmx - c2x, cmy - c2y)
479479

480480
if parallel_test == -1:
481-
cbook._warn_external(
481+
_api.warn_external(
482482
"Lines do not intersect. A straight line is used instead.")
483483
cos_t1, sin_t1 = get_cos_sin(c1x, c1y, c2x, c2y)
484484
cos_t2, sin_t2 = cos_t1, sin_t1

lib/matplotlib/colorbar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@
219219
def _set_ticks_on_axis_warn(*args, **kw):
220220
# a top level function which gets put in at the axes'
221221
# set_xticks and set_yticks by ColorbarBase.__init__.
222-
cbook._warn_external("Use the colorbar set_ticks() method instead.")
222+
_api.warn_external("Use the colorbar set_ticks() method instead.")
223223

224224

225225
class _ColorbarAutoLocator(ticker.MaxNLocator):
@@ -721,7 +721,7 @@ def set_ticklabels(self, ticklabels, update_ticks=True):
721721
if update_ticks:
722722
self.update_ticks()
723723
else:
724-
cbook._warn_external("set_ticks() must have been called.")
724+
_api.warn_external("set_ticks() must have been called.")
725725
self.stale = True
726726

727727
def minorticks_on(self):

lib/matplotlib/contour.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ def __init__(self, ax, *args,
827827

828828
if self.filled:
829829
if self.linewidths is not None:
830-
cbook._warn_external('linewidths is ignored by contourf')
830+
_api.warn_external('linewidths is ignored by contourf')
831831
# Lower and upper contour levels.
832832
lowers, uppers = self._get_lowers_and_uppers()
833833
# Ensure allkinds can be zipped below.
@@ -878,9 +878,10 @@ def __init__(self, ax, *args,
878878
self.changed() # set the colors
879879

880880
if kwargs:
881-
s = ", ".join(map(repr, kwargs))
882-
cbook._warn_external('The following kwargs were not used by '
883-
'contour: ' + s)
881+
_api.warn_external(
882+
'The following kwargs were not used by contour: ' +
883+
", ".join(map(repr, kwargs))
884+
)
884885

885886
def get_transform(self):
886887
"""
@@ -1111,7 +1112,7 @@ def _process_contour_level_args(self, args):
11111112
levels_in = self.levels[inside]
11121113
if len(levels_in) == 0:
11131114
self.levels = [self.zmin]
1114-
cbook._warn_external(
1115+
_api.warn_external(
11151116
"No contour levels were found within the data range.")
11161117

11171118
if self.filled and len(self.levels) < 2:
@@ -1433,8 +1434,7 @@ def _contour_args(self, args, kwargs):
14331434
self.zmin = float(z.min())
14341435
if self.logscale and self.zmin <= 0:
14351436
z = ma.masked_where(z <= 0, z)
1436-
cbook._warn_external('Log scale: values of z <= 0 have been '
1437-
'masked')
1437+
_api.warn_external('Log scale: values of z <= 0 have been masked')
14381438
self.zmin = float(z.min())
14391439
self._process_contour_level_a C3AE rgs(args)
14401440
return (x, y, z)

lib/matplotlib/dates.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ def get_locator(self, dmin, dmax):
14091409
break
14101410
else:
14111411
if not (self.interval_multiples and freq == DAILY):
1412-
cbook._warn_external(
1412+
_api.warn_external(
14131413
f"AutoDateLocator was unable to pick an appropriate "
14141414
f"interval for this date range. It may be necessary "
14151415
f"to add an interval value to the AutoDateLocator's "
@@ -1448,7 +1448,7 @@ def get_locator(self, dmin, dmax):
14481448
else:
14491449
locator = MicrosecondLocator(interval, tz=self.tz)
14501450
if date2num(dmin) > 70 * 365 and interval < 1000:
1451-
cbook._warn_external(
1451+
_api.warn_external(
14521452
'Plotting microsecond time intervals for dates far from '
14531453
f'the epoch (time origin: {get_epoch()}) is not well-'
14541454
'supported. See matplotlib.dates.set_epoch to change the '

0 commit comments

Comments
 (0)
0