Permalink
Browse files

Merge pull request #1643 from NelleV/cleanup_cbook

Clean up code in cbook
  • Loading branch information...
2 parents 99d1a2f + 1c97376 commit 0bf445a4b1044d4fea743800506329965ff49ff1 @efiring efiring committed Feb 18, 2013
Showing with 17 additions and 93 deletions.
  1. +11 −93 lib/matplotlib/cbook.py
  2. +6 −0 lib/matplotlib/tests/test_cbook.py
View
@@ -28,7 +28,6 @@
import numpy.ma as ma
-
import types
@@ -43,8 +42,6 @@
if sys.version_info[0] >= 3:
def unicode_safe(s):
- import matplotlib
-
try:
preferredencoding = locale.getpreferredencoding(
matplotlib.rcParams['axes.formatter.use_locale']).strip()
@@ -79,7 +76,7 @@ def unicode_safe(s):
return unicode(s, preferredencoding)
-class converter:
+class converter(object):
"""
Base class for handling string -> python type with support for
missing values
@@ -274,12 +271,14 @@ class CallbackRegistry:
functions). This technique was shared by Peter Parente on his
`"Mindtrove" blog
<http://mindtrove.info/articles/python-weak-references/>`_.
+
+ .. deprecated:: 1.3.0
"""
def __init__(self, *args):
if len(args):
warnings.warn(
- 'CallbackRegistry no longer requires a list of callback types.'
- ' Ignoring arguments',
+ "CallbackRegistry no longer requires a list of callback "
+ "types. Ignoring arguments. *args will be removed in 1.5",
mplDeprecation)
self.callbacks = dict()
self._cid = 0
@@ -538,7 +537,6 @@ def to_filehandle(fname, flag='rU', return_opened=False):
"""
if is_string_like(fname):
if fname.endswith('.gz'):
- import gzip
# get rid of 'U' in flag for gzipped files.
flag = flag.replace('U', '')
fh = gzip.open(fname, flag)
@@ -581,7 +579,8 @@ def get_sample_data(fname, asfileobj=True):
if matplotlib.rcParams['examples.directory']:
root = matplotlib.rcParams['examples.directory']
else:
- root = os.path.join(os.path.dirname(__file__), "mpl-data", "sample_data")
+ root = os.path.join(os.path.dirname(__file__),
+ "mpl-data", "sample_data")
path = os.path.join(root, fname)
if asfileobj:
@@ -1298,7 +1297,7 @@ def xy(self, i0=0, isub=1):
def plot(self, i0=0, isub=1, fig=None):
if fig is None:
- from pylab import figure, show
+ from pylab import figure
fig = figure()
ax = fig.add_subplot(111)
@@ -1608,8 +1607,9 @@ def delete_masked_points(*args):
return margs
+# FIXME I don't think this is used anywhere
def unmasked_index_ranges(mask, compressed=True):
- '''
+ """
Find index ranges where *mask* is *False*.
*mask* will be flattened if it is not already 1-D.
@@ -1639,8 +1639,7 @@ def unmasked_index_ranges(mask, compressed=True):
Prior to the transforms refactoring, this was used to support
masked arrays in Line2D.
-
- '''
+ """
mask = mask.reshape(mask.size)
m = np.concatenate(((1,), mask, (1,)))
indices = np.arange(len(mask) + 1)
@@ -1668,79 +1667,6 @@ def unmasked_index_ranges(mask, compressed=True):
ls_mapper.update([(ls[1], ls[0]) for ls in _linestyles])
-def less_simple_linear_interpolation(x, y, xi, extrap=False):
- """
- This function has been moved to matplotlib.mlab -- please import
- it from there
- """
- # deprecated from cbook in 0.98.4
- warnings.warn('less_simple_linear_interpolation has been moved to '
- 'matplotlib.mlab -- please import it from there',
- mplDeprecation)
- import matplotlib.mlab as mlab
- return mlab.less_simple_linear_interpolation(x, y, xi, extrap=extrap)
-
-
-def vector_lengths(X, P=2.0, axis=None):
- """
- This function has been moved to matplotlib.mlab -- please import
- it from there
- """
- # deprecated from cbook in 0.98.4
- warnings.warn('vector_lengths has been moved to matplotlib.mlab -- '
- 'please import it from there', mplDeprecation)
- import matplotlib.mlab as mlab
- return mlab.vector_lengths(X, P=2.0, axis=axis)
-
-
-def distances_along_curve(X):
- """
- This function has been moved to matplotlib.mlab -- please import
- it from there
- """
- # deprecated from cbook in 0.98.4
- warnings.warn('distances_along_curve has been moved to matplotlib.mlab '
- '-- please import it from there', mplDeprecation)
- import matplotlib.mlab as mlab
- return mlab.distances_along_curve(X)
-
-
-def path_length(X):
- """
- This function has been moved to matplotlib.mlab -- please import
- it from there
- """
- # deprecated from cbook in 0.98.4
- warnings.warn('path_length has been moved to matplotlib.mlab '
- '-- please import it from there', mplDeprecation)
- import matplotlib.mlab as mlab
- return mlab.path_length(X)
-
-
-def is_closed_polygon(X):
- """
- This function has been moved to matplotlib.mlab -- please import
- it from there
- """
- # deprecated from cbook in 0.98.4
- warnings.warn('is_closed_polygon has been moved to matplotlib.mlab '
- '-- please import it from there', mplDeprecation)
- import matplotlib.mlab as mlab
- return mlab.is_closed_polygon(X)
-
-
-def quad2cubic(q0x, q0y, q1x, q1y, q2x, q2y):
- """
- This function has been moved to matplotlib.mlab -- please import
- it from there
- """
- # deprecated from cbook in 0.98.4
- warnings.warn('quad2cubic has been moved to matplotlib.mlab -- please '
- 'import it from there', mplDeprecation)
- import matplotlib.mlab as mlab
- return mlab.quad2cubic(q0x, q0y, q1x, q1y, q2x, q2y)
-
-
def align_iterators(func, *iterables):
"""
This generator takes a bunch of iterables that are ordered by func
@@ -1893,11 +1819,3 @@ def _check_output(*popenargs, **kwargs):
check_output = subprocess.check_output
else:
check_output = _check_output
-
-
-if __name__ == '__main__':
- assert(allequal([1, 1, 1]))
- assert(not allequal([1, 1, 0]))
- assert(allequal([]))
- assert(allequal(('a', 'a')))
- assert(not allequal(('a', 'b')))
@@ -78,3 +78,9 @@ def test_rgba(self):
assert_array_equal(actual[1], expected[1])
+def test_allequal():
+ assert(cbook.allequal([1, 1, 1]))
+ assert(not cbook.allequal([1, 1, 0]))
+ assert(cbook.allequal([]))
+ assert(cbook.allequal(('a', 'a')))
+ assert(not cbook.allequal(('a', 'b')))

0 comments on commit 0bf445a

Please sign in to comment.