8000 Merge pull request #7568 from anntzer/deprecate-unused-cbook · matplotlib/matplotlib@a15d5c8 · GitHub
[go: up one dir, main page]

Skip to content

Commit a15d5c8

Browse files
authored
Merge pull request #7568 from anntzer/deprecate-unused-cbook
Deprecate unused functions in cbook.
2 parents f99a985 + d85e2b7 commit a15d5c8

File tree

5 files changed

+66
-41
lines changed

5 files changed

+66
-41
lines changed

lib/matplotlib/artist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ def findobj(self, match=None, include_self=True):
10061006
if match is None: # always return True
10071007
def matchfunc(x):
10081008
return True
1009-
elif cbook.issubclass_safe(match, Artist):
1009+
elif isinstance(match, type) and issubclass(match, Artist):
10101010
def matchfunc(x):
10111011
return isinstance(x, match)
10121012
elif callable(match):

lib/matplotlib/cbook.py

Lines changed: 61 additions & 24 deletions
< F987 tr class="diff-line-row">
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ def warn_deprecated(
128128

129129

130130
def deprecated(since, message='', name='', alternative='', pending=False,
131-
obj_type='function'):
131+
obj_type=None):
132132
"""
133-
Decorator to mark a function as deprecated.
133+
Decorator to mark a function or a class as deprecated.
134134
135135
Parameters
136136
----------
@@ -176,33 +176,49 @@ def the_function_to_deprecate():
176176
pass
177177
178178
"""
179-
def deprecate(func, message=message, name=name, alternative=alternative,
179+
def deprecate(obj, message=message, name=name, alternative=alternative,
180180
pending=pending):
181-
import functools
182181
import textwrap
183182

184-
if isinstance(func, classmethod):
185-
func = func.__func__
186-
is_classmethod = True
187-
else:
188-
is_classmethod = False
189-
190183
if not name:
191-
name = func.__name__
184+
name = obj.__name__
185+
186+
if isinstance(obj, type):
187+
obj_type = "class"
188+
old_doc = obj.__doc__
189+
func = obj.__init__
190+
def finalize(wrapper, new_doc):
191+
try:
192+
obj.__doc__ = new_doc
193+
except AttributeError:
194+
pass # cls.__doc__ is not writeable on Py2.
195+
obj.__init__ = wrapper
196+
return obj
197+
else:
198+
obj_type = "function"
199+
if isinstance(obj, classmethod):
200+
func = obj.__func__
201+
old_doc = func.__doc__
202+
def finalize(wrapper, new_doc):
203+
wrapper = functools.wraps(func)(wrapper)
204+
wrapper.__doc__ = new_doc
205+
return classmethod(wrapper)
206+
else:
207+
func = obj
208+
old_doc = func.__doc__
209+
def finalize(wrapper, new_doc):
210+
wrapper = functools.wraps(func)(wrapper)
211+
wrapper.__doc__ = new_doc
212+
return wrapper
192213

193214
message = _generate_deprecation_message(
194215
since, message, name, alternative, pending, obj_type)
195216

196-
@functools.wraps(func)
197-
def deprecated_func(*args, **kwargs):
217+
def wrapper(*args, **kwargs):
198218
warnings.warn(message, mplDeprecation, stacklevel=2)
199-
200219
return func(*args, **kwargs)
201220

202-
old_doc = deprecated_func.__doc__
203-
if not old_doc:
204-
old_doc = ''
205-
old_doc = textwrap.dedent(old_doc).strip('\n')
221+
old_doc = textwrap.dedent(old_doc or '').strip('\n')
206222
message = message.strip()
207223
new_doc = (('\n.. deprecated:: %(since)s'
208224
'\n %(message)s\n\n' %
@@ -212,11 +228,7 @@ def deprecated_func(*args, **kwargs):
212228
# docutils when the original docstring was blank.
213229
new_doc += r'\ '
214230

215-
deprecated_func.__doc__ = new_doc
216-
217-
if is_classmethod:
218-
deprecated_func = classmethod(deprecated_func)
219-
return deprecated_func
231+
return finalize(wrapper, new_doc)
220232

221233
return deprecate
222234

@@ -249,6 +261,7 @@ def unicode_safe(s):
249261
return s
250262

251263

264+
@deprecated('2.1')
252265
class converter(object):
253266
"""
254267
Base class for handling string -> python type with support for
@@ -267,12 +280,14 @@ def is_missing(self, s):
267280
return not s.strip() or s == self.missing
268281

269282

283+
@deprecated('2.1')
270284
class tostr(converter):
271285
"""convert to string or None"""
272286
def __init__(self, missing='Null', missingval=''):
273287
converter.__init__(self, missing=missing, missingval=missingval)
274288

275289

290+
@deprecated('2.1')
276291
class todatetime(converter):
277292
"""convert to a datetime or None"""
278293
def __init__(self, fmt='%Y-%m-%d', missing='Null', missingval=None):
@@ -287,6 +302,7 @@ def __call__(self, s):
287302
return datetime.datetime(*tup[:6])
288303

289304

305+
@deprecated('2.1')
290306
class todate(converter):
291307
"""convert to a date or None"""
292308
def __init__(self, fmt='%Y-%m-%d', missing='Null', missingval=None):
@@ -301,6 +317,7 @@ def __call__(self, s):
301317
return datetime.date(*tup[:3])
302318

303319

320+
@deprecated('2.1')
304321
class tofloat(converter):
305322
"""convert to a float or None"""
306323
def __init__(self, missing='Null', missingval=None):
@@ -313,6 +330,7 @@ def __call__(self, s):
313330
return float(s)
314331

315332

333+
@deprecated('2.1')
316334
class toint(converter):
317335
"""convert to an int or None"""
318336
def __init__(self, missing='Null', missingval=None):
@@ -656,6 +674,7 @@ def __repr__(self):
656674
in keys])
657675

658676

677+
@deprecated('2.1')
659678
def unique(x):
660679
"""Return a list of unique elements of *x*"""
661680
return list(set(x))
@@ -851,6 +870,7 @@ def flatten(seq, scalarp=is_scalar_or_string):
851870
yield subitem
852871

853872

873+
@deprecated('2.1', "sorted(..., key=itemgetter(...))")
854874
class Sorter(object):
855875
"""
856876
Sort by attribute or item
@@ -899,6 +919,7 @@ def byAttribute(self, data, attributename, inplace=1):
899919
__call__ = byItem
900920

901921

922+
@deprecated('2.1')
902923
class Xlator(dict):
903924
"""
904925
All-in-one multiple-string-substitution class
@@ -931,6 +952,7 @@ def xlat(self, text):
931952
return self._make_regex().sub(self, text)
932953

933954

955+
@deprecated('2.1')
934956
def soundex(name, len=4):
935957
""" soundex module conforming to Odell-Russell algorithm """
936958

@@ -959,6 +981,7 @@ def soundex(name, len=4):
959981
return (sndx + (len * '0'))[:len]
960982

961983

984+
@deprecated('2.1')
962985
class Null(object):
963986
""" Null objects always and reliably "do nothing." """
964987

@@ -1028,6 +1051,7 @@ def __call__(self, path):
10281051
get_realpath_and_stat = GetRealpathAndStat()
10291052

10301053

1054+
@deprecated('2.1')
10311055
def dict_delall(d, keys):
10321056
"""delete all of the *keys* from the :class:`dict` *d*"""
10331057
for key in keys:
@@ -1037,6 +1061,7 @@ def dict_delall(d, keys):
10371061
pass
10381062

10391063

1064+
@deprecated('2.1')
10401065
class RingBuffer(object):
10411066
""" class that implements a not-yet-full buffer """
10421067
def __init__(self, size_max):
@@ -1088,6 +1113,7 @@ def get_split_ind(seq, N):
10881113
return len(seq)
10891114

10901115

1116+
@deprecated('2.1', alternative='textwrap.TextWrapper')
10911117
def wrap(prefix, text, cols):
10921118
"""wrap *text* with *prefix* at length *cols*"""
10931119
pad = ' ' * len(prefix.expandtabs())
@@ -1202,6 +1228,7 @@ def get_recursive_filelist(args):
12021228
return [f for f in files if not os.path.islink(f)]
12031229

12041230

1231+
@deprecated('2.1')
12051232
def pieces(seq, num=2):
12061233
"""Break up the *seq* into *num* tuples"""
12071234
start = 0
@@ -1213,6 +1240,7 @@ def pieces(seq, num=2):
12131240
start += num
12141241

12151242

1243+
@deprecated('2.1')
12161244
def exception_to_str(s=None):
12171245
if six.PY3:
12181246
sh = io.StringIO()
@@ -1224,6 +1252,7 @@ def exception_to_str(s=None):
12241252
return sh.getvalue()
12251253

12261254

1255+
@deprecated('2.1')
12271256
def allequal(seq):
12281257
"""
12291258
Return *True* if all elements of *seq* compare equal. If *seq* is
@@ -1239,6 +1268,7 @@ def allequal(seq):
12391268
return True
12401269

12411270

1271+
@deprecated('2.1')
12421272
def alltrue(seq):
12431273
"""
12441274
Return *True* if all elements of *seq* evaluate to *True*. If
@@ -1252,6 +1282,7 @@ def alltrue(seq):
12521282
return True
12531283

12541284

1285+
@deprecated('2.1')
12551286
def onetrue(seq):
12561287
"""
12571288
Return *True* if one element of *seq* is *True*. It *seq* is
@@ -1265,6 +1296,7 @@ def onetrue(seq):
12651296
return False
12661297

12671298

1299+
@deprecated('2.1')
12681300
def allpairs(x):
12691301
"""
12701302
return all possible pairs in sequence *x*
@@ -1391,6 +1423,7 @@ def remove(self, o):
13911423
self.push(thiso)
13921424

13931425

1426+
@deprecated('2.1')
13941427
def finddir(o, match, case=False):
13951428
"""
13961429
return all attributes of *o* which match string in match. if case
@@ -1405,6 +1438,7 @@ def finddir(o, match, case=False):
14051438
return [orig for name, orig in names if name.find(match) >= 0]
14061439

14071440

1441+
@deprecated('2.1')
14081442
def reverse_dict(d):
14091443
"""reverse the dictionary -- may lose data if values are not unique!"""
14101444
return {v: k for k, v in six.iteritems(d)}
@@ -1476,6 +1510,7 @@ def safezip(*args):
14761510
return list(zip(*args))
14771511

14781512

1513+
@deprecated('2.1')
14791514
def issubclass_safe(x, klass):
14801515
"""return issubclass(x, klass) and return False on a TypeError"""
14811516

@@ -1720,6 +1755,7 @@ def simple_linear_interpolation(a, steps):
17201755
return result
17211756

17221757

1758+
@deprecated('2.1', alternative='shutil.rmtree')
17231759
def recursive_remove(path):
17241760
if os.path.isdir(path):
17251761
for fname in (glob.glob(os.path.join(path, '*')) +
@@ -2018,6 +2054,7 @@ def _compute_conf_interval(data, med, iqr, bootstrap):
20182054

20192055

20202056
# FIXME I don't think this is used anywhere
2057+
@deprecated('2.1')
20212058
def unmasked_index_ranges(mask, compressed=True):
20222059
"""
20232060
Find index ranges where *mask* is *False*.
@@ -2071,7 +2108,7 @@ def unmasked_index_ranges(mask, compressed=True):
20712108
# The ls_mapper maps short codes for line style to their full name used by
20722109
# backends; the reverse mapper is for mapping full names to short ones.
20732110
ls_mapper = {'-': 'solid', '--': 'dashed', '-.': 'dashdot', ':': 'dotted'}
2074-
ls_mapper_r = reverse_dict(ls_mapper)
2111+
ls_mapper_r = {v: k for k, v in six.iteritems(ls_mapper)}
20752112

20762113

20772114
def align_iterators(func, *iterables):

lib/matplotlib/mlab.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3423,12 +3423,9 @@ def less_simple_linear_interpolation(x, y, xi, extrap=False):
34233423
only for a small number of points in relatively non-intensive use
34243424
cases. For real linear interpolation, use scipy.
34253425
"""
3426-
if cbook.is_scalar(xi):
3427-
xi = [xi]
3428-
34293426
x = np.asarray(x)
34303427
y = np.asarray(y)
3431-
xi = np.asarray(xi)
3428+
xi = np.atleast_1d(xi)
34323429

34333430
s = list(y.shape)
34343431
s[0] = len(xi)

lib/matplotlib/tests/test_cbook.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,6 @@ def test_rgba(self):
113113
assert_array_equal(actual[1], expected[1])
114114

115115

116-
def test_allequal():
117-
assert cbook.allequal([1, 1, 1])
118-
assert not cbook.allequal([1, 1, 0])
119-
assert cbook.allequal([])
120-
assert cbook.allequal(('a', 'a'))
121-
assert not cbook.allequal(('a', 'b'))
122-
123-
124116
class Test_boxplot_stats(object):
125117
def setup(self):
126118
np.random.seed(937)

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,18 +1519,17 @@ def plot(self, xs, ys, *args, **kwargs):
15191519

15201520
argsi = 0
15211521
# First argument is array of zs
1522-
if len(args) > 0 and cbook.iterable(args[0]) and \
1523-
len(xs) == len(args[0]) :
1522+
if args and cbook.iterable(args[0]) and len(xs) == len(args[0]):
15241523
# So, we know that it is an array with
15251524
# first dimension the same as xs.
15261525
# Next, check to see if the data contained
15271526
# therein (if any) is scalar (and not another array).
1528-
if len(args[0]) == 0 or cbook.is_scalar(args[0][0]) :
1527+
if len(args[0]) == 0 or cbook.is_scalar(args[0][0]):
15291528
zs = args[argsi]
15301529
argsi += 1
15311530

15321531
# First argument is z value
1533-
elif len(args) > 0 and cbook.is_scalar(args[0]):
1532+
elif args and cbook.is_scalar(args[0]):
15341533
zs = args[argsi]
15351534
argsi += 1
15361535

0 commit comments

Comments
 (0)
0