Skip to content

Commit f23860d

Browse files
timhoffmQuLogic
andauthored
Move from cbook._warn_external() to _api.warn_external()
* Move from cbook._warn_external() to _api.warn_external() * Fix typo Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
1 parent eda3939 commit f23860d

38 files changed

+161
-170
lines changed

lib/matplotlib/_constrained_layout.py

+7-7
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

+1-1
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

+1-2
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(f"Rasterization of '{self}' will be ignored")
906905

907906
self._rasterized = rasterized
908907

lib/matplotlib/axes/_axes.py

+6-7
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

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

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

24632463
if tight is not None:
@@ -3443,19 +3443,19 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False,
34433443
# so only grab the limits if we really need them.
34443444
old_left, old_right = self.get_xlim()
34453445
if left <= 0:
3446-
cbook._warn_external(
3446+
_api.warn_external(
34473447
'Attempted to set non-positive left xlim on a '
34483448
'log-scaled axis.\n'
34493449
'Invalid limit will be ignored.')
34503450
left = old_left
34513451
if right <= 0:
3452-
cbook._warn_external(
3452+
_api.warn_external(
34533453
'Attempted to set non-positive right xlim on a '
34543454
'log-scaled axis.\n'
34553455
'Invalid limit will be ignored.')
34563456
right = old_right
34573457
if left == right:
3458-
cbook._warn_external(
3458+
_api.warn_external(
34593459
f"Attempting to set identical left == right == {left} results "
34603460
f"in singular transformations; automatically expanding.")
34613461
reverse = left > right
@@ -3769,19 +3769,19 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
37693769
# so only grab the limits if we really need them.
37703770
old_bottom, old_top = self.get_ylim()
37713771
if bottom <= 0:
3772-
cbook._warn_external(
3772+
_api.warn_external(
37733773
'Attempted to set non-positive bottom ylim on a '
37743774
'log-scaled axis.\n'
37753775
'Invalid limit will be ignored.')
37763776
bottom = old_bottom
37773777
if top <= 0:
3778-
cbook._warn_external(
3778+
_api.warn_external(
37793779
'Attempted to set non-positive top ylim on a '
37803780
'log-scaled axis.\n'
37813781
'Invalid limit will be ignored.')
37823782
top = old_top
37833783
if bottom == top:
3784-
cbook._warn_external(
3784+
_api.warn_external(
37853785
f"Attempting to set identical bottom == top == {bottom} "
37863786
f"results in singular transformations; automatically "
37873787
f"expanding.")
@@ -4068,7 +4068,7 @@ def _set_view_from_bbox(self, bbox, direction='in',
40684068
xzc + xwidth/2./scl, yzc + ywidth/2./scl]
40694069
elif len(bbox) != 4:
40704070
# should be len 3 or 4 but nothing else
4071-
cbook._warn_external(
4071+
_api.warn_external(
40724072
"Warning in _set_view_from_bbox: bounding box is not a tuple "
40734073
"of length 3 or 4. Ignoring the view change.")
40744074
return
@@ -4212,7 +4212,7 @@ def format_deltas(key, dx, dy):
42124212
result = (mtransforms.Bbox(newpoints)
42134213
.transformed(p.trans_inverse))
42144214
except OverflowError:
4215-
cbook._warn_external('Overflow while panning')
4215+
_api.warn_external('Overflow while panning')
42164216
return
42174217
else:
42184218
return

lib/matplotlib/axes/_secondary_axes.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import numpy as np
22

33
from matplotlib import _api
4-
import matplotlib.cbook as cbook
54
import matplotlib.docstring as docstring
65
import matplotlib.ticker as mticker
76
from matplotlib.axes._base import _AxesBase, _TransformedBoundsLocator
@@ -246,7 +245,7 @@ def set_aspect(self, *args, **kwargs):
246245
Secondary axes cannot set the aspect ratio, so calling this just
247246
sets a warning.
248247
"""
249-
cbook._warn_external("Secondary axes can't set the aspect ratio")
248+
_api.warn_external("Secondary axes can't set the aspect ratio")
250249

251250
def set_color(self, color):
252251
"""

lib/matplotlib/axis.py

+5-5
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

+1-1
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

+5-6
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(f"ToolManager does not control tool {name}")
442441
return None
443442
return self._tools[name]

lib/matplotlib/backend_tools.py

+1-1
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

+5-5
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

+1-1
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

+2-2
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import numpy as np
1010

11-
from matplotlib import _api, cbook
11+
from matplotlib import _api
1212

1313

1414
# same algorithm as 3.8's math.comb
@@ -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/cbook/__init__.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929

3030
import matplotlib
3131
from matplotlib import _api, _c_internal_utils
32-
from matplotlib._api import (
33-
warn_external as _warn_external, classproperty as _classproperty)
32+
from matplotlib._api import classproperty as _classproperty
3433
from matplotlib._api.deprecation import (
3534
deprecated, warn_deprecated, MatplotlibDeprecationWarning, mplDeprecation)
3635

@@ -346,8 +345,8 @@ def _local_over_kwdict(
346345
if out is None:
347346
out = kwarg_val
348347
else:
349-
_warn_external('"%s" keyword argument will be ignored' % key,
350-
warning_cls)
348+
_api.warn_external(f'"{key}" keyword argument will be ignored',
349+
warning_cls)
351350
return out
352351

353352

lib/matplotlib/colorbar.py

+2-2
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):

0 commit comments

Comments
 (0)