Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 11 additions & 93 deletions lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import numpy.ma as ma



import types


Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1608,8 +1607,9 @@ def delete_masked_points(*args):
return margs


# FIXME I don't think this is used anywhere
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, not used in mpl. That's also the case with several other things in cbook.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll deprecate the unused method in another PR.

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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')))
6 changes: 6 additions & 0 deletions lib/matplotlib/tests/test_cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')))