X Tutup
Skip to content
Merged
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
97 changes: 46 additions & 51 deletions lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,13 @@ def is_missing(self, s):


class tostr(converter):
'convert to string or None'
"""convert to string or None"""
def __init__(self, missing='Null', missingval=''):
converter.__init__(self, missing=missing, missingval=missingval)


class todatetime(converter):
'convert to a datetime or None'
"""convert to a datetime or None"""
def __init__(self, fmt='%Y-%m-%d', missing='Null', missingval=None):
'use a :func:`time.strptime` format string for conversion'
converter.__init__(self, missing, missingval)
Expand All @@ -289,9 +289,9 @@ def __call__(self, s):


class todate(converter):
'convert to a date or None'
"""convert to a date or None"""
def __init__(self, fmt='%Y-%m-%d', missing='Null', missingval=None):
'use a :func:`time.strptime` format string for conversion'
"""use a :func:`time.strptime` format string for conversion"""
converter.__init__(self, missing, missingval)
self.fmt = fmt

Expand All @@ -303,7 +303,7 @@ def __call__(self, s):


class tofloat(converter):
'convert to a float or None'
"""convert to a float or None"""
def __init__(self, missing='Null', missingval=None):
converter.__init__(self, missing)
self.missingval = missingval
Expand All @@ -315,7 +315,7 @@ def __call__(self, s):


class toint(converter):
'convert to an int or None'
"""convert to an int or None"""
def __init__(self, missing='Null', missingval=None):
converter.__init__(self, missing)

Expand All @@ -326,7 +326,7 @@ def __call__(self, s):


class _BoundMethodProxy(object):
'''
"""
Our own proxy object which enables weak references to bound and unbound
methods and arbitrary callables. Pulls information about the function,
class, and instance out of a bound method. Stores a weak reference to the
Expand All @@ -337,7 +337,7 @@ class _BoundMethodProxy(object):
@license: The BSD License

Minor bugfixes by Michael Droettboom
'''
"""
def __init__(self, cb):
self._hash = hash(cb)
self._destroy_callbacks = []
Expand Down Expand Up @@ -386,13 +386,13 @@ def __setstate__(self, statedict):
self.inst = ref(inst)

def __call__(self, *args, **kwargs):
'''
"""
Proxy for a call to the weak referenced object. Take
arbitrary params to pass to the callable.

Raises `ReferenceError`: When the weak reference refers to
a dead object
'''
"""
if self.inst is not None and self.inst() is None:
raise ReferenceError
elif self.inst is not None:
Expand All @@ -408,10 +408,10 @@ def __call__(self, *args, **kwargs):
return mtd(*args, **kwargs)

def __eq__(self, other):
'''
"""
Compare the held function and instance with that held by
another proxy.
'''
"""
try:
if self.inst is None:
return self.func == other.func and other.inst is None
Expand All @@ -421,9 +421,9 @@ def __eq__(self, other):
return False

def __ne__(self, other):
'''
"""
Inverse of __eq__.
'''
"""
return not self.__eq__(other)

def __hash__(self):
Expand Down Expand Up @@ -626,7 +626,7 @@ def local_over_kwdict(local_var, kwargs, *keys):


def strip_math(s):
'remove latex formatting from mathtext'
"""remove latex formatting from mathtext"""
remove = (r'\mathdefault', r'\rm', r'\cal', r'\tt', r'\it', '\\', '{', '}')
s = s[1:-1]
for r in remove:
Expand Down Expand Up @@ -658,12 +658,12 @@ def __repr__(self):


def unique(x):
'Return a list of unique elements of *x*'
"""Return a list of unique elements of *x*"""
return list(six.iterkeys(dict([(val, 1) for val in x])))


def iterable(obj):
'return true if *obj* is iterable'
"""return true if *obj* is iterable"""
try:
iter(obj)
except TypeError:
Expand All @@ -672,7 +672,7 @@ def iterable(obj):


def is_string_like(obj):
'Return True if *obj* looks like a string'
"""Return True if *obj* looks like a string"""
if isinstance(obj, six.string_types):
return True
# numpy strings are subclass of str, ma strings are not
Expand All @@ -689,9 +689,7 @@ def is_string_like(obj):


def is_sequence_of_strings(obj):
"""
Returns true if *obj* is iterable and contains strings
"""
"""Returns true if *obj* is iterable and contains strings"""
if not iterable(obj):
return False
if is_string_like(obj) and not isinstance(obj, np.ndarray):
Expand All @@ -707,9 +705,7 @@ def is_sequence_of_strings(obj):


def is_hashable(obj):
"""
Returns true if *obj* can be hashed
"""
"""Returns true if *obj* can be hashed"""
try:
hash(obj)
except TypeError:
Expand All @@ -718,7 +714,7 @@ def is_hashable(obj):


def is_writable_file_like(obj):
'return true if *obj* looks like a file object with a *write* method'
"""return true if *obj* looks like a file object with a *write* method"""
return hasattr(obj, 'write') and six.callable(obj.write)


Expand All @@ -736,12 +732,12 @@ def file_requires_unicode(x):


def is_scalar(obj):
'return true if *obj* is not string like and is not iterable'
"""return true if *obj* is not string like and is not iterable"""
return not is_string_like(obj) and not iterable(obj)


def is_numlike(obj):
'return true if *obj* looks like a number'
"""return true if *obj* looks like a number"""
try:
obj + 1
except:
Expand Down Expand Up @@ -1034,7 +1030,7 @@ def __call__(self, path):


def dict_delall(d, keys):
'delete all of the *keys* from the :class:`dict` *d*'
"""delete all of the *keys* from the :class:`dict` *d*"""
for key in keys:
try:
del d[key]
Expand Down Expand Up @@ -1084,17 +1080,17 @@ def get_split_ind(seq, N):
.
"""

sLen = 0
s_len = 0
# todo: use Alex's xrange pattern from the cbook for efficiency
for (word, ind) in zip(seq, xrange(len(seq))):
sLen += len(word) + 1 # +1 to account for the len(' ')
if sLen >= N:
s_len += len(word) + 1 # +1 to account for the len(' ')
if s_len >= N:
return ind
return len(seq)


def wrap(prefix, text, cols):
'wrap *text* with *prefix* at length *cols*'
"""wrap *text* with *prefix* at length *cols*"""
pad = ' ' * len(prefix.expandtabs())
available = cols - len(pad)

Expand Down Expand Up @@ -1208,7 +1204,7 @@ def get_recursive_filelist(args):


def pieces(seq, num=2):
"Break up the *seq* into *num* tuples"
"""Break up the *seq* into *num* tuples"""
start = 0
while 1:
item = seq[start:start + num]
Expand Down Expand Up @@ -1284,7 +1280,7 @@ def allpairs(x):
class maxdict(dict):
"""
A dictionary with a maximum size; this doesn't override all the
relevant methods to contrain size, just setitem, so use with
relevant methods to constrain the size, just setitem, so use with
caution
"""
def __init__(self, maxsize):
Expand Down Expand Up @@ -1313,7 +1309,7 @@ def __init__(self, default=None):
self._default = default

def __call__(self):
'return the current element, or None'
"""return the current element, or None"""
if not len(self._elements):
return self._default
else:
Expand All @@ -1326,14 +1322,14 @@ def __getitem__(self, ind):
return self._elements.__getitem__(ind)

def forward(self):
'move the position forward and return the current element'
N = len(self._elements)
if self._pos < N - 1:
"""move the position forward and return the current element"""
n = len(self._elements)
if self._pos < n - 1:
self._pos += 1
return self()

def back(self):
'move the position back and return the current element'
"""move the position back and return the current element"""
if self._pos > 0:
self._pos -= 1
return self()
Expand All @@ -1349,7 +1345,7 @@ def push(self, o):
return self()

def home(self):
'push the first element onto the top of the stack'
"""push the first element onto the top of the stack"""
if not len(self._elements):
return
self.push(self._elements[0])
Expand All @@ -1359,7 +1355,7 @@ def empty(self):
return len(self._elements) == 0

def clear(self):
'empty the stack'
"""empty the stack"""
self._pos = -1
self._elements = []

Expand Down Expand Up @@ -1411,7 +1407,7 @@ def finddir(o, match, case=False):


def reverse_dict(d):
'reverse the dictionary -- may lose data if values are not unique!'
"""reverse the dictionary -- may lose data if values are not unique!"""
return dict([(v, k) for k, v in six.iteritems(d)])


Expand All @@ -1424,7 +1420,7 @@ def restrict_dict(d, keys):


def report_memory(i=0): # argument may go away
'return the memory consumed by process'
"""return the memory consumed by process"""
from matplotlib.compat.subprocess import Popen, PIPE
pid = os.getpid()
if sys.platform == 'sunos5':
Expand Down Expand Up @@ -1473,7 +1469,7 @@ def report_memory(i=0): # argument may go away


def safezip(*args):
'make sure *args* are equal len before zipping'
"""make sure *args* are equal len before zipping"""
Nx = len(args[0])
for i, arg in enumerate(args[1:]):
if len(arg) != Nx:
Expand All @@ -1482,7 +1478,7 @@ def safezip(*args):


def issubclass_safe(x, klass):
'return issubclass(x, klass) and return False on a TypeError'
"""return issubclass(x, klass) and return False on a TypeError"""

try:
return issubclass(x, klass)
Expand Down Expand Up @@ -2120,7 +2116,7 @@ def __call__(self, key):
# iteration
iters = [myiter(it) for it in iterables]
minvals = minkey = True
while 1:
while True:
minvals = ([_f for _f in [it.key for it in iters] if _f])
if minvals:
minkey = min(minvals)
Expand Down Expand Up @@ -2198,7 +2194,7 @@ def _reshape_2D(X):


def violin_stats(X, method, points=100):
'''
"""
Returns a list of dictionaries of data which can be used to draw a series
of violin plots. See the `Returns` section below to view the required keys
of the dictionary. Users can skip this function and pass a user-defined set
Expand Down Expand Up @@ -2235,7 +2231,7 @@ def violin_stats(X, method, points=100):
- median: The median value for this column of data.
- min: The minimum value for this column of data.
- max: The maximum value for this column of data.
'''
"""

# List of dictionaries describing each of the violins.
vpstats = []
Expand Down Expand Up @@ -2318,7 +2314,7 @@ def _step_validation(x, *args):
args = tuple(np.asanyarray(y) for y in args)
x = np.asanyarray(x)
if x.ndim != 1:
raise ValueError("x must be 1 dimenional")
raise ValueError("x must be 1 dimensional")
if len(args) == 0:
raise ValueError("At least one Y value must be passed")

Expand Down Expand Up @@ -2501,8 +2497,7 @@ def safe_first_element(obj):


def sanitize_sequence(data):
"""Converts dictview object to list
"""
"""Converts dictview object to list"""
if six.PY3 and isinstance(data, collections.abc.MappingView):
return list(data)
return data
Expand Down
X Tutup