8000 Merge pull request #1596 from ivanov/mpl-deprecation-warnings-1.2.x · matplotlib/matplotlib@6a12658 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6a12658

Browse files
committed
Merge pull request #1596 from ivanov/mpl-deprecation-warnings-1.2.x
new MatplotlibDeprecationWarning class (against 1.2.x)
2 parents e64fb8c + 929d359 commit 6a12658

File tree

12 files changed

+80
-45
lines changed

12 files changed

+80
-45
lines changed

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 mplDeprecation
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-08-11 Fix path-closing bug in patches.Polygon, so that regardless
212
of whether the path is the initial one or was subsequently
313
set by set_xy(), get_xy() will return a closed path if and

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< 8000 code class="diff-text syntax-highlighted-line addition">+
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: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import matplotlib.ticker as mticker
3737
import matplotlib.transforms as mtransforms
3838
import matplotlib.tri as mtri
39+
from matplotlib import MatplotlibDeprecationWarning as mplDeprecation
3940
from matplotlib.container import BarContainer, ErrorbarContainer, StemContainer
4041

4142
iterable = cbook.iterable
@@ -150,8 +151,7 @@ def set_default_color_cycle(clist):
150151
151152
"""
152153
rcParams['axes.color_cycle'] = clist
153-
warnings.warn("Set rcParams['axes.color_cycle'] directly",
154-
DeprecationWarning)
154+
warnings.warn("Set rcParams['axes.color_cycle'] directly", mplDeprecation)
155155

156156

157157
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 mplDeprecation('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', mplDeprecation)
13841384
return self.patch
13851385

13861386
def get_legend(self):
@@ -3112,13 +3112,13 @@ def connect(self, s, func):
31123112
disconnect to disconnect from the axes event
31133113
31143114
"""
3115-
raise DeprecationWarning('use the callbacks CallbackRegistry instance '
3116-
'instead')
3115+
raise mplDeprecation('use the callbacks CallbackRegistry instance '
3116+
'instead')
31173117

31183118
def disconnect(self, cid):
31193119
"""disconnect from the Axes event."""
3120-
raise DeprecationWarning('use the callbacks CallbackRegistry instance '
3121-
'instead')
3120+
raise mplDeprecation('use the callbacks CallbackRegistry instance '
3121+
'instead')
31223122

31233123
def get_children(self):
31243124
"""return a list of child artists"""
@@ -3167,10 +3167,10 @@ def pick(self, *args):
31673167
each child artist will fire a pick event if mouseevent is over
31683168
the artist and the artist has picker set
31693169
"""
3170-
if len(args)>1:
3171-
raise DeprecationWarning('New pick API implemented -- '
3172-
'see API_CHANGES in the src distribution')
3173-
martist.Artist.pick(self,args[0])
3170+
if len(args) > 1:
3171+
raise mplDeprecation('New pick API implemented -- '
3172+
'see API_CHANGES in the src distribution')
3173+
martist.Artist.pick(self, args[0])
31743174

31753175
def __pick(self, x, y, trans=None, among=None):
31763176
"""
@@ -3730,9 +3730,9 @@ def hlines(self, y, xmin, xmax, colors='k', linestyles='solid',
37303730
.. plot:: mpl_examples/pylab_examples/hline_demo.py
37313731
"""
37323732
if kwargs.get('fmt') is not None:
3733-
raise DeprecationWarning('hlines now uses a '
3734-
'collections.LineCollection and not a '
3735-
'list of Line2D to draw; see API_CHANGES')
3733+
raise mplDeprecation('hlines now uses a '
3734+
'collections.LineCollection and not a '
3735+
'list of Line2D to draw; see API_CHANGES')
3736 F438 3736

37373737
# We do the conversion first since not all unitized data is uniform
37383738
# process the unit information
@@ -3810,9 +3810,9 @@ def vlines(self, x, ymin, ymax, colors='k', linestyles='solid',
38103810
"""
38113811

38123812
if kwargs.get('fmt') is not None:
3813-
raise DeprecationWarning('vlines now uses a '
3814-
'collections.LineCollection and not a '
3815-
'list of Line2D to draw; see API_CHANGES')
3813+
raise mplDeprecation('vlines now uses a '
3814+
'collections.LineCollection and not a '
3815+
'list of Line2D to draw; see API_CHANGES')
38163816

38173817
self._process_unit_info(xdata=x, ydata=[ymin, ymax], kwargs=kwargs)
38183818

@@ -6086,7 +6086,7 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,
60866086
edgecolors = 'none'
60876087
warnings.warn(
60886088
'''replace "faceted=False" with "edgecolors='none'"''',
6089-
DeprecationWarning) #2008/04/18
6089+
mplDeprecation) # 2008/04/18
60906090

60916091
sym = None
60926092
symstyle = 0
@@ -7999,7 +7999,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
79997999

80008000

80018001
if kwargs.get('width') is not None:
8002-
raise DeprecationWarning(
8002+
raise mplDeprecation(
80038003
'hist now uses the rwidth to give relative width '
80048004
'and not absolute width')
80058005

@@ -8715,7 +8715,7 @@ def spy(self, Z, precision=0, marker=None, markersize=None,
87158715
"""
87168716
if precision is None:
87178717
precision = 0
8718-
warnings.DeprecationWarning("Use precision=0 instead of None")
8718+
warnings.warn("Use precision=0 instead of None", mplDeprecation)
87198719
# 2008/10/03
87208720
if marker is None and markersize is None and hasattr(Z, 'tocoo'):
87218721
marker = 's'

lib/matplotlib/backend_bases.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import matplotlib.tight_bbox as tight_bbox
4747
import matplotlib.textpath as textpath
4848
from matplotlib.path import Path
49+
from matplotlib import MatplotlibDeprecationWarning as mplDeprecation
4950

5051
try:
5152
from PIL import Image
@@ -2274,7 +2275,7 @@ def start_event_loop_default(self,timeout=0):
22742275
"""
22752276
str = "Using default event loop until function specific"
22762277
str += " to this GUI is implemented"
2277-
warnings.warn(str,DeprecationWarning)
2278+
warnings.warn(str, mplDeprecation)
22782279

22792280
if timeout <= 0: timeout = np.inf
22802281
timestep = 0.01

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 mplDeprecation
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+
mplDeprecation)
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 mplDeprecation
2829

2930
# Debugging settings here...
3031
# Debug level set here. If the debug level is less than 5, information
@@ -792,7 +793,7 @@ def Printer_Init(self):
792793
793794
Deprecated.
794795
"""
795-
warnings.warn("Printer* methods will be removed", DeprecationWarning)
796+
warnings.warn("Printer* methods will be removed", mplDeprecation)
796797
self.printerData = wx.PrintData()
797798
self.printerData.SetPaperId(wx.PAPER_LETTER)
798799
self.printerData.SetPrintMode(wx.PRINT_MODE_PRINTER)
@@ -806,7 +807,7 @@ def Printer_Init(self):
806807

807808
def _get_printerData(self):
808809
if self._printerData is None:
809-
warnings.warn("Printer* methods will be removed", DeprecationWarning)
810+
warnings.warn("Printer* methods will be removed", mplDeprecation)
810811
self._printerData = wx.PrintData()
811812
self._printerData.SetPaperId(wx.PAPER_LETTER)
812813
self._printerData.SetPrintMode(wx.PRINT_MODE_PRINTER)
@@ -815,7 +816,7 @@ def _get_printerData(self):
815816

816817
def _get_printerPageData(self):
817818
if self._printerPageData is None:
818-
warnings.warn("Printer* methods will be removed", DeprecationWarning)
819+
warnings.warn("Printer* methods will be removed", mplDeprecation)
819820
self._printerPageData= wx.PageSetupDialogData()
820821
self._printerPageData.SetMarginBottomRight((25,25))
821822
self._printerPageData.SetMarginTopLeft((25,25))
@@ -834,7 +835,7 @@ def Printer_Setup(self, event=None):
834835
dmsg = """Width of output figure in inches.
835836
The current aspect ratio will be kept."""
836837

837-
warnings.warn("Printer* methods will be removed", DeprecationWarning)
838+
warnings.warn("Printer* methods will be removed", mplDeprecation)
838839
dlg = wx.Dialog(self, -1, 'Page Setup for Printing' , (-1,-1))
839840
df = dlg.GetFont()
840841
df.SetWeight(wx.NORMAL)
@@ -897,7 +898,7 @@ def Printer_Setup2(self, event=None):
897898
Deprecated.
898899
"""
899900

900-
warnings.warn("Printer* methods will be removed", DeprecationWarning)
901+
warnings.warn("Printer* methods will be removed", mplDeprecation)
901902
if hasattr(self, 'printerData'):
902903
data = wx.PageSetupDialogData()
903904
data.SetPrintData(self.printerData)
@@ -921,7 +922,7 @@ def Printer_Preview(self, event=None):
921922
922923
Deprecated.
923924
"""
924-
warnings.warn("Printer* methods will be removed", DeprecationWarning)
925+
warnings.warn("Printer* methods will be removed", mplDeprecation)
925926
po1 = PrintoutWx(self, width=self.printer_width,
926927
margin=self.printer_margin)
927928
po2 = PrintoutWx(self, width=self.printer_width,
@@ -947,7 +948,7 @@ def Printer_Print(self, event=None):
947948
948949
Deprecated.
949950
"""
950-
warnings.warn("Printer* methods will be removed", DeprecationWarning)
951+
warnings.warn("Printer* methods will be removed", mplDeprecation)
951952
pdd = wx.PrintDialogData()
952953
# SetPrintData for 2.4 combatibility
953954
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 mplDeprecation
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+
mplDeprecation)
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+
mplDeprecation)
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', mplDeprecation)
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', mplDeprecation)
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', mplDeprecation)
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', mplDeprecation)
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', mplDeprecation)
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 mplDeprecation
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+
mplDeprecation)
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 mplDeprecation
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+
mplDeprecation) # 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", mplDeprecation) # 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", mplDeprecation) # 2009/06/13
14301432

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

0 commit comments

Comments
 (0)
0