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

Skip to content

Commit 394b1aa

Browse files
committed
new MatplotlibDeprecationWarning class
In light of the fact that Python builtin DeprecationWarnings are ignored by default as of Python 2.7 (see link below), this class was put in to allow for the signaling of deprecation, but via UserWarnings which are not ignored by default. http://docs.python.org/dev/whatsnew/2.7.html#the-future-for-python-2-x Prior to this commit: ``` In [1]: %pylab Welcome to pylab, a matplotlib-based Python environment [backend: agg]. For more information, type 'help(pylab)'. In [2]: mlab.liaupunov([1,2], np.diff) Out[2]: 0.0 ``` After this commit: ``` In [1]: %pylab Welcome to pylab, a matplotlib-based Python environment [backend: agg]. For more information, type 'help(pylab)'. In [2]: mlab.liaupunov([1,2], np.diff) /home/pi/.local/lib/python2.7/site-packages/matplotlib/mlab.py:1212: MatplotlibDeprecationWarning: This does not belong in matplotlib and will be removed mDeprecation) # 2009/06/13 Out[2]: 0.0 ```
1 parent dc1d0ee commit 394b1aa

12 files changed

Lines changed: 78 additions & 44 deletions

File tree

CHANGELOG

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2012-12-05 Added MatplotlibDeprecationWarning class for signaling deprecation.
2+
Matplotlib developers can use this class as follows:
3+
4+
from matplotlib import MatplotlibDeprecationWarning as mDeprecation
5+
6+
In light of the fact that Python builtin DeprecationWarnings are
7+
ignored by default as of Python 2.7, this class was put in to allow
8+
for the signaling of deprecation, but via UserWarnings which are
9+
not ignored by default. - PI
10+
111
2012-11-27 Added the *mtext* parameter for supplying matplotlib.text.Text
212
instances to RendererBase.draw_tex and RendererBase.draw_text.
313
This allows backends to utilize additional text attributes, like

lib/matplotlib/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,20 @@
122122
if not hasattr(sys, 'argv'): # for modpython
123123
sys.argv = ['modpython']
124124

125+
126+
class MatplotlibDeprecationWarning(UserWarning):
127+
"""
128+
A class for issuing deprecation warnings for Matplotlib users.
129+
130+
In light of the fact that Python builtin DeprecationWarnings are ignored
131+
by default as of Python 2.7 (see link below), this class was put in to
132+
allow for the signaling of deprecation, but via UserWarnings which are not
133+
ignored by default.
134+
135+
http://docs.python.org/dev/whatsnew/2.7.html#the-future-for-python-2-x
136+
"""
137+
pass
138+
125139
"""
126140
Manage user customizations through a rc file.
127141

lib/matplotlib/axes.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import matplotlib.ticker as mticker
3838
import matplotlib.transforms as mtransforms
3939
import matplotlib.tri as mtri
40+
from matplotlib import MatplotlibDeprecationWarning as mDeprecation
4041
from matplotlib.container import BarContainer, ErrorbarContainer, StemContainer
4142

4243
iterable = cbook.iterable
@@ -154,8 +155,7 @@ def set_default_color_cycle(clist):
154155
155156
"""
156157
rcParams['axes.color_cycle'] = clist
157-
warnings.warn("Set rcParams['axes.color_cycle'] directly",
158-
DeprecationWarning)
158+
warnings.warn("Set rcParams['axes.color_cycle'] directly", mplDeprecation)
159159

160160

161161
class _process_plot_var_args(object):
@@ -1376,11 +1376,11 @@ def get_child_artists(self):
13761376
13771377
.. deprecated:: 0.98
13781378
"""
1379-
raise DeprecationWarning('Use get_children instead')
1379+
raise mDeprecation('Use get_children instead')
13801380

13811381
def get_frame(self):
13821382
"""Return the axes Rectangle frame"""
1383-
warnings.warn('use ax.patch instead', DeprecationWarning)
1383+
warnings.warn('use ax.patch instead', mDeprecation)
13841384
return self.patch
13851385

13861386
def get_legend(self):
@@ -3135,13 +3135,13 @@ def connect(self, s, func):
31353135
disconnect to disconnect from the axes event
31363136
31373137
"""
3138-
raise DeprecationWarning('use the callbacks CallbackRegistry instance '
3139-
'instead')
3138+
raise mDeprecation('use the callbacks CallbackRegistry instance '
3139+
'instead')
31403140

31413141
def disconnect(self, cid):
31423142
"""disconnect from the Axes event."""
3143-
raise DeprecationWarning('use the callbacks CallbackRegistry instance '
3144-
'instead')
3143+
raise mDeprecation('use the callbacks CallbackRegistry instance '
3144+
'instead')
31453145

31463146
def get_children(self):
31473147
"""return a list of child artists"""
@@ -3192,8 +3192,8 @@ def pick(self, *args):
31923192
the artist and the artist has picker set
31933193
"""
31943194
if len(args) > 1:
3195-
raise DeprecationWarning('New pick API implemented -- '
3196-
'see API_CHANGES in the src distribution')
3195+
raise mDeprecation('New pick API implemented -- '
3196+
'see API_CHANGES in the src distribution')
31973197
martist.Artist.pick(self, args[0])
31983198

31993199
### Labelling
@@ -3691,9 +3691,9 @@ def hlines(self, y, xmin, xmax, colors='k', linestyles='solid',
36913691
.. plot:: mpl_examples/pylab_examples/hline_demo.py
36923692
"""
36933693
if kwargs.get('fmt') is not None:
3694-
raise DeprecationWarning('hlines now uses a '
3695-
'collections.LineCollection and not a '
3696-
'list of Line2D to draw; see API_CHANGES')
3694+
raise mDeprecation('hlines now uses a '
3695+
'collections.LineCollection and not a '
3696+
'list of Line2D to draw; see API_CHANGES')
36973697

36983698
# We do the conversion first since not all unitized data is uniform
36993699
# process the unit information
@@ -3773,9 +3773,9 @@ def vlines(self, x, ymin, ymax, colors='k', linestyles='solid',
37733773
"""
37743774

37753775
if kwargs.get('fmt') is not None:
3776-
raise DeprecationWarning('vlines now uses a '
3777-
'collections.LineCollection and not a '
3778-
'list of Line2D to draw; see API_CHANGES')
3776+
raise mDeprecation('vlines now uses a '
3777+
'collections.LineCollection and not a '
3778+
'list of Line2D to draw; see API_CHANGES')
37793779

37803780
self._process_unit_info(xdata=x, ydata=[ymin, ymax], kwargs=kwargs)
37813781

@@ -6074,7 +6074,7 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,
60746074
edgecolors = 'none'
60756075
warnings.warn(
60766076
'''replace "faceted=False" with "edgecolors='none'"''',
6077-
DeprecationWarning) # 2008/04/18
6077+
mDeprecation) # 2008/04/18
60786078

60796079
# to be API compatible
60806080
if marker is None and not (verts is None):
@@ -8002,7 +8002,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
80028002
"orientation kwarg %s is not recognized" % orientation)
80038003

80048004
if kwargs.get('width') is not None:
8005-
raise DeprecationWarning(
8005+
raise mDeprecation(
80068006
'hist now uses the rwidth to give relative width '
80078007
'and not absolute width')
80088008

@@ -8735,7 +8735,7 @@ def spy(self, Z, precision=0, marker=None, markersize=None,
87358735
"""
87368736
if precision is None:
87378737
precision = 0
8738-
warnings.DeprecationWarning("Use precision=0 instead of None")
8738+
warnings.warn("Use precision=0 instead of None", mDeprecation)
87398739
# 2008/10/03
87408740
if marker is None and markersize is None and hasattr(Z, 'tocoo'):
87418741
marker = 's'

lib/matplotlib/backend_bases.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import matplotlib.tight_bbox as tight_bbox
4949
import matplotlib.textpath as textpath
5050
from matplotlib.path import Path
51+
from matplotlib import MatplotlibDeprecationWarning as mDeprecation
5152

5253
try:
5354
from PIL import Image
@@ -2306,7 +2307,7 @@ def start_event_loop_default(self, timeout=0):
23062307
"""
23072308
str = "Using default event loop until function specific"
23082309
str += " to this GUI is implemented"
2309-
warnings.warn(str, DeprecationWarning)
2310+
warnings.warn(str, mDeprecation)
23102311

23112312
if timeout <= 0:
23122313
timeout = np.inf

lib/matplotlib/backends/backend_qt.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
import sys
55
import warnings
66

7+
from matplotlib import MatplotlibDeprecationWarning as mDeprecation
8+
79
warnings.warn("QT3-based backends are deprecated and will be removed after"
810
" the v1.2.x release. Use the equivalent QT4 backend instead.",
9-
DeprecationWarning)
11+
mDeprecation)
1012

1113
import matplotlib
1214
from matplotlib import verbose

lib/matplotlib/backends/backend_wx.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import numpy as np
2727

28+
from matplotlib import MatplotlibDeprecationWarning as mDeprecation
2829

2930
# Debugging settings here...
3031
# Debug level set here. If the debug level is less than 5, information
@@ -788,7 +789,7 @@ def Printer_Init(self):
788789
789790
Deprecated.
790791
"""
791-
warnings.warn("Printer* methods will be removed", DeprecationWarning)
792+
warnings.warn("Printer* methods will be removed", mDeprecation)
792793
self.printerData = wx.PrintData()
793794
self.printerData.SetPaperId(wx.PAPER_LETTER)
794795
self.printerData.SetPrintMode(wx.PRINT_MODE_PRINTER)
@@ -802,7 +803,7 @@ def Printer_Init(self):
802803

803804
def _get_printerData(self):
804805
if self._printerData is None:
805-
warnings.warn("Printer* methods will be removed", DeprecationWarning)
806+
warnings.warn("Printer* methods will be removed", mDeprecation)
806807
self._printerData = wx.PrintData()
807808
self._printerData.SetPaperId(wx.PAPER_LETTER)
808809
self._printerData.SetPrintMode(wx.PRINT_MODE_PRINTER)
@@ -811,7 +812,7 @@ def _get_printerData(self):
811812

812813
def _get_printerPageData(self):
813814
if self._printerPageData is None:
814-
warnings.warn("Printer* methods will be removed", DeprecationWarning)
815+
warnings.warn("Printer* methods will be removed", mDeprecation)
815816
self._printerPageData= wx.PageSetupDialogData()
816817
self._printerPageData.SetMarginBottomRight((25,25))
817818
self._printerPageData.SetMarginTopLeft((25,25))
@@ -830,7 +831,7 @@ def Printer_Setup(self, event=None):
830831
dmsg = """Width of output figure in inches.
831832
The current aspect ratio will be kept."""
832833

833-
warnings.warn("Printer* methods will be removed", DeprecationWarning)
834+
warnings.warn("Printer* methods will be removed", mDeprecation)
834835
dlg = wx.Dialog(self, -1, 'Page Setup for Printing' , (-1,-1))
835836
df = dlg.GetFont()
836837
df.SetWeight(wx.NORMAL)
@@ -893,7 +894,7 @@ def Printer_Setup2(self, event=None):
893894
Deprecated.
894895
"""
895896

896-
warnings.warn("Printer* methods will be removed", DeprecationWarning)
897+
warnings.warn("Printer* methods will be removed", mDeprecation)
897898
if hasattr(self, 'printerData'):
898899
data = wx.PageSetupDialogData()
899900
data.SetPrintData(self.printerData)
@@ -917,7 +918,7 @@ def Printer_Preview(self, event=None):
917918
918919
Deprecated.
919920
"""
920-
warnings.warn("Printer* methods will be removed", DeprecationWarning)
921+
warnings.warn("Printer* methods will be removed", mDeprecation)
921922
po1 = PrintoutWx(self, width=self.printer_width,
922923
margin=self.printer_margin)
923924
po2 = PrintoutWx(self, width=self.printer_width,
@@ -943,7 +944,7 @@ def Printer_Print(self, event=None):
943944
944945
Deprecated.
945946
"""
946-
warnings.warn("Printer* methods will be removed", DeprecationWarning)
947+
warnings.warn("Printer* methods will be removed", mDeprecation)
947948
pdd = wx.PrintDialogData()
948949
# SetPrintData for 2.4 combatibility
949950
pdd.SetPrintData(self.printerData)

lib/matplotlib/cbook.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from weakref import ref, WeakKeyDictionary
2323

2424
import matplotlib
25+
from matplotlib import MatplotlibDeprecationWarning as mDeprecation
2526

2627
import numpy as np
2728
import numpy.ma as ma
@@ -281,7 +282,7 @@ def __init__(self, *args):
281282
warnings.warn(
282283
'CallbackRegistry no longer requires a list of callback types.'
283284
' Ignoring arguments',
284-
DeprecationWarning)
285+
mDeprecation)
285286
self.callbacks = dict()
286287
self._cid = 0
287288
self._func_cid_map = {}
@@ -1676,7 +1677,7 @@ def less_simple_linear_interpolation(x, y, xi, extrap=False):
16761677
# deprecated from cbook in 0.98.4
16771678
warnings.warn('less_simple_linear_interpolation has been moved to '
16781679
'matplotlib.mlab -- please import it from there',
1679-
DeprecationWarning)
1680+
mDeprecation)
16801681
import matplotlib.mlab as mlab
16811682
return mlab.less_simple_linear_interpolation(x, y, xi, extrap=extrap)
16821683

@@ -1688,7 +1689,7 @@ def vector_lengths(X, P=2.0, axis=None):
16881689
"""
16891690
# deprecated from cbook in 0.98.4
16901691
warnings.warn('vector_lengths has been moved to matplotlib.mlab -- '
1691-
'please import it from there', DeprecationWarning)
1692+
'please import it from there', mDeprecation)
16921693
import matplotlib.mlab as mlab
16931694
return mlab.vector_lengths(X, P=2.0, axis=axis)
16941695

@@ -1700,7 +1701,7 @@ def distances_along_curve(X):
17001701
"""
17011702
# deprecated from cbook in 0.98.4
17021703
warnings.warn('distances_along_curve has been moved to matplotlib.mlab '
1703-
'-- please import it from there', DeprecationWarning)
1704+
'-- please import it from there', mDeprecation)
17041705
import matplotlib.mlab as mlab
17051706
return mlab.distances_along_curve(X)
17061707

@@ -1712,7 +1713,7 @@ def path_length(X):
17121713
"""
17131714
# deprecated from cbook in 0.98.4
17141715
warnings.warn('path_length has been moved to matplotlib.mlab '
1715-
'-- please import it from there', DeprecationWarning)
1716+
'-- please import it from there', mDeprecation)
17161717
import matplotlib.mlab as mlab
17171718
return mlab.path_length(X)
17181719

@@ -1724,7 +1725,7 @@ def is_closed_polygon(X):
17241725
"""
17251726
# deprecated from cbook in 0.98.4
17261727
warnings.warn('is_closed_polygon has been moved to matplotlib.mlab '
1727-
'-- please import it from there', DeprecationWarning)
1728+
'-- please import it from there', mDeprecation)
17281729
import matplotlib.mlab as mlab
17291730
return mlab.is_closed_polygon(X)
17301731

@@ -1736,7 +1737,7 @@ def quad2cubic(q0x, q0y, q1x, q1y, q2x, q2y):
17361737
"""
17371738
# deprecated from cbook in 0.98.4
17381739
warnings.warn('quad2cubic has been moved to matplotlib.mlab -- please '
1739-
'import it from there', DeprecationWarning)
1740+
'import it from there', mDeprecation)
17401741
import matplotlib.mlab as mlab
17411742
return mlab.quad2cubic(q0x, q0y, q1x, q1y, q2x, q2y)
17421743

lib/matplotlib/legend.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from matplotlib.offsetbox import DraggableOffsetBox
3232

3333
from matplotlib.container import ErrorbarContainer, BarContainer, StemContainer
34+
from matplotlib import MatplotlibDeprecationWarning as mDeprecation
3435
import legend_handler
3536

3637

@@ -278,7 +279,7 @@ def __init__(self, parent, handles, labels,
278279
# counter part is None.
279280
if localdict[k] is not None and localdict[v] is None:
280281
warnings.warn("Use '%s' instead of '%s'." % (v, k),
281-
DeprecationWarning)
282+
mDeprecation)
282283
setattr(self, v, localdict[k] * axessize_fontsize)
283284
continue
284285

lib/matplotlib/mlab.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
import numpy as np
149149
ma = np.ma
150150
from matplotlib import verbose
151+
from matplotlib import MatplotlibDeprecationWarning as mDeprecation
151152

152153
import matplotlib.cbook as cbook
153154
from matplotlib import docstring
@@ -1207,7 +1208,8 @@ def liaupunov(x, fprime):
12071208
It also seems that this function's name is badly misspelled.
12081209
"""
12091210

1210-
warnings.warn("This does not belong in matplotlib and will be removed", DeprecationWarning) # 2009/06/13
1211+
warnings.warn("This does not belong in matplotlib and will be removed",
1212+
mDeprecation) # 2009/06/13
12111213

12121214
return np.mean(np.log(np.absolute(fprime(x))))
12131215

@@ -1339,7 +1341,7 @@ def save(fname, X, fmt='%.18e',delimiter=' '):
13391341
for comma-separated values.
13401342
"""
13411343

1342-
warnings.warn("use numpy.savetxt", DeprecationWarning) # 2009/06/13
1344+
warnings.warn("use numpy.savetxt", mDeprecation) # 2009/06/13
13431345

13441346
if cbook.is_string_like(fname):
13451347
if fname.endswith('.gz'):
@@ -1426,7 +1428,7 @@ def load(fname,comments='#',delimiter=None, converters=None,skiprows=0,
14261428
Exercises many of these options.
14271429
"""
14281430

1429-
warnings.warn("use numpy.loadtxt", DeprecationWarning) # 2009/06/13
1431+
warnings.warn("use numpy.loadtxt", mDeprecation) # 2009/06/13
14301432

14311433
if converters is None: converters = {}
14321434
fh = cbook.to_filehandle(fname)

lib/matplotlib/nxutils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import warnings
22

33
from matplotlib import path
4+
from matplotlib import MatplotlibDeprecationWarning as mDeprecation
45

56
def pnpoly(x, y, xyverts):
67
"""
@@ -19,7 +20,7 @@ def pnpoly(x, y, xyverts):
1920
warnings.warn(
2021
"nxutils is deprecated. Use matplotlib.path.Path.contains_point"
2122
" instead.",
22-
DeprecationWarning)
23+
mDeprecation)
2324

2425
p = path.Path(xyverts)
2526
return p.contains_point(x, y)
@@ -44,7 +45,7 @@ def points_inside_poly(xypoints, xyverts):
4445
warnings.warn(
4546
"nxutils is deprecated. Use matplotlib.path.Path.contains_points"
4647
" instead.",
47-
DeprecationWarning)
48+
mDeprecation)
4849

4950
p = path.Path(xyverts)
5051
return p.contains_points(xypoints)

0 commit comments

Comments
 (0)