8000 Merge pull request #1643 from NelleV/cleanup_cbook · matplotlib/matplotlib@0bf445a · GitHub
[go: up one dir, main page]

Skip to content

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 0bf445a

Browse files
committed
Merge pull request #1643 from NelleV/cleanup_cbook
Clean up code in cbook
2 parents 99d1a2f + 1c97376 commit 0bf445a

File tree

2 files changed

+17
-93
lines changed

2 files changed

+17
-93
lines changed

lib/matplotlib/cbook.py

Lines changed: 11 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import numpy.ma as ma
2929

3030

31-
3231
import types
3332

3433

@@ -43,8 +42,6 @@
4342

4443
if sys.version_info[0] >= 3:
4544
def unicode_safe(s):
46-
import matplotlib
47-
4845
try:
4946
preferredencoding = locale.getpreferredencoding(
5047
matplotlib.rcParams['axes.formatter.use_locale']).strip()
@@ -79,7 +76,7 @@ def unicode_safe(s):
7976
return unicode(s, preferredencoding)
8077

8178

82-
class converter:
79+
class converter(object):
8380
"""
8481
Base class for handling string -> python type with support for
8582
missing values
@@ -274,12 +271,14 @@ class CallbackRegistry:
274271
functions). This technique was shared by Peter Parente on his
275272
`"Mindtrove" blog
276273
<http://mindtrove.info/articles/python-weak-references/>`_.
274+
275+
.. deprecated:: 1.3.0
277276
"""
278277
def __init__(self, *args):
279278
if len(args):
280279
warnings.warn(
281-
'CallbackRegistry no longer requires a list of callback types.'
282-
' Ignoring arguments',
280+
"CallbackRegistry no longer requires a list of callback "
281+
"types. Ignoring arguments. *args will be removed in 1.5",
283282
mplDeprecation)
284283
self.callbacks = dict()
285284
self._cid = 0
@@ -538,7 +537,6 @@ def to_filehandle(fname, flag='rU', return_opened=False):
538537
"""
539538
if is_string_like(fname):
540539
if fname.endswith('.gz'):
541-
import gzip
542540
# get rid of 'U' in flag for gzipped files.
543541
flag = flag.replace('U', '')
544542
fh = gzip.open(fname, flag)
@@ -581,7 +579,8 @@ def get_sample_data(fname, asfileobj=True):
581579
if matplotlib.rcParams['examples.directory']:
582580
root = matplotlib.rcParams['examples.directory']
583581
else:
584-
root = os.path.join(os.path.dirname(__file__), "mpl-data", "sample_data")
582+
root = os.path.join(os.path.dirname(__file__),
583+
"mpl-data", "sample_data")
585584
path = os.path.join(root, fname)
586585

587586
if asfileobj:
@@ -1298,7 +1297,7 @@ def xy(self, i0=0, isub=1):
12981297

12991298
def plot(self, i0=0, isub=1, fig=None):
13001299
if fig is None:
1301-
from pylab import figure, show
1300+
from pylab import figure
13021301
fig = figure()
13031302

13041303
ax = fig.add_subplot(111)
@@ -1608,8 +1607,9 @@ def delete_masked_points(*args):
16081607
return margs
16091608

16101609

1610+
# FIXME I don't think this is used anywhere
16111611
def unmasked_index_ranges(mask, compressed=True):
1612-
'''
1612+
"""
16131613
Find index ranges where *mask* is *False*.
16141614
16151615
*mask* will be flattened if it is not already 1-D.
@@ -1639,8 +1639,7 @@ def unmasked_index_ranges(mask, compressed=True):
16391639
16401640
Prior to the transforms refactoring, this was used to support
16411641
masked arrays in Line2D.
1642-
1643-
'''
1642+
"""
16441643
mask = mask.reshape(mask.size)
16451644
m = np.concatenate(((1,), mask, (1,)))
16461645
indices = np.arange(len(mask) + 1)
@@ -1668,79 +1667,6 @@ def unmasked_index_ranges(mask, compressed=True):
16681667
ls_mapper.update([(ls[1], ls[0]) for ls in _linestyles])
16691668

16701669

1671-
def less_simple_linear_interpolation(x, y, xi, extrap=False):
1672-
"""
1673-
This function has been moved to matplotlib.mlab -- please import
1674-
it from there
1675-
"""
1676-
# deprecated from cbook in 0.98.4
1677-
warnings.warn('less_simple_linear_interpolation has been moved to '
1678-
'matplotlib.mlab -- please import it from there',
1679-
mplDeprecation)
1680-
import matplotlib.mlab as mlab
1681-
return mlab.less_simple_linear_interpolation(x, y, xi, extrap=extrap)
1682-
1683-
1684-
def vector_lengths(X, P=2.0, axis=None):
1685-
"""
1686-
This function has been moved to matplotlib.mlab -- please import
1687-
it from there
1688-
"""
1689-
# deprecated from cbook in 0.98.4
1690-
warnings.warn('vector_lengths has been moved to matplotlib.mlab -- '
1691-
'please import it from there', mplDeprecation)
1692-
import matplotlib.mlab as mlab
1693-
return mlab.vector_lengths(X, P=2.0, axis=axis)
1694-
1695-
1696-
def distances_along_curve(X):
1697-
"""
1698-
This function has been moved to matplotlib.mlab -- please import
1699-
it from there
1700-
"""
1701-
# deprecated from cbook in 0.98.4
1702-
warnings.warn('distances_along_curve has been moved to matplotlib.mlab '
1703-
'-- please import it from there', mplDeprecation)
1704-
import matplotlib.mlab as mlab
1705-
return mlab.distances_along_curve(X)
1706-
1707-
1708-
def path_length(X):
1709-
"""
1710-
This function has been moved to matplotlib.mlab -- please import
1711-
it from there
1712-
"""
1713-
# deprecated from cbook in 0.98.4
1714-
warnings.warn('path_length has been moved to matplotlib.mlab '
1715-
'-- please import it from there', mplDeprecation)
1716-
import matplotlib.mlab as mlab
1717-
return mlab.path_length(X)
1718-
1719-
1720-
def is_closed_polygon(X):
1721-
"""
1722-
This function has been moved to matplotlib.mlab -- please import
1723-
it from there
1724-
"""
1725-
# deprecated from cbook in 0.98.4
1726-
warnings.warn('is_closed_polygon has been moved to matplotlib.mlab '
1727-
'-- please import it from there', mplDeprecation)
1728-
import matplotlib.mlab as mlab
1729-
return mlab.is_closed_polygon(X)
1730-
1731-
1732-
def quad2cubic(q0x, q0y, q1x, q1y, q2x, q2y):
1733-
"""
1734-
This function has been moved to matplotlib.mlab -- please import
1735-
it from there
1736-
"""
1737-
# deprecated from cbook in 0.98.4
1738-
warnings.warn('quad2cubic has been moved to matplotlib.mlab -- please '
1739-
'import it from there', mplDeprecation)
1740-
import matplotlib.mlab as mlab
1741-
return mlab.quad2cubic(q0x, q0y, q1x, q1y, q2x, q2y)
1742-
1743-
17441670
def align_iterators(func, *iterables):
17451671
"""
17461672
This generator takes a bunch of iterables that are ordered by func
@@ -1893,11 +1819,3 @@ def _check_output(*popenargs, **kwargs):
18931819
check_output = subprocess.check_output
18941820
else:
18951821
check_output = _check_output
1896-
1897-
1898-
if __name__ == '__main__':
1899-
assert(allequal([1, 1, 1]))
1900-
assert(not allequal([1, 1, 0]))
1901-
assert(allequal([]))
1902-
assert(allequal(('a', 'a')))
1903-
assert(not allequal(('a', 'b')))

lib/matplotlib/tests/test_cbook.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,9 @@ def test_rgba(self):
7878
assert_array_equal(actual[1], expected[1])
7979

8080

81+
def test_allequal():
82+
assert(cbook.allequal([1, 1, 1]))
83+
assert(not cbook.allequal([1, 1, 0]))
84+
assert(cbook.allequal([]))
85+
assert(cbook.allequal(('a', 'a')))
86+
assert(not cbook.allequal(('a', 'b')))

0 commit comments

Comments
 (0)
0