From 3771324860e141faecead56898c538cf18df663a Mon Sep 17 00:00:00 2001 From: Mher Kazandjian Date: Mon, 17 Oct 2016 01:40:02 +0200 Subject: [PATCH 1/3] fixed some docstring styles and fixed typos Signed-off-by: Mher Kazandjian --- lib/matplotlib/cbook.py | 87 +++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 46 deletions(-) diff --git a/lib/matplotlib/cbook.py b/lib/matplotlib/cbook.py index 0e8c0f50e150..dc998e6682d6 100644 --- a/lib/matplotlib/cbook.py +++ b/lib/matplotlib/cbook.py @@ -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) @@ -289,7 +289,7 @@ 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' converter.__init__(self, missing, missingval) @@ -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 @@ -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) @@ -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 @@ -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 = [] @@ -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: @@ -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): @@ -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: @@ -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: @@ -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 @@ -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): @@ -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: @@ -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) @@ -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: @@ -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] @@ -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) @@ -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 contain size, just setitem, so use with caution """ def __init__(self, maxsize): @@ -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: @@ -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() @@ -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]) @@ -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 = [] @@ -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)]) @@ -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': @@ -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: @@ -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) @@ -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 @@ -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 = [] @@ -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") @@ -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 From 821810ed2615118706eff7c32775aab573023af3 Mon Sep 17 00:00:00 2001 From: Mher Kazandjian Date: Mon, 17 Oct 2016 01:50:30 +0200 Subject: [PATCH 2/3] some style fixes and typo fixes in docstrings --- lib/matplotlib/cbook.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/cbook.py b/lib/matplotlib/cbook.py index dc998e6682d6..fb7834b578b4 100644 --- a/lib/matplotlib/cbook.py +++ b/lib/matplotlib/cbook.py @@ -291,7 +291,7 @@ def __call__(self, s): class todate(converter): """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 @@ -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 @@ -1204,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] @@ -2116,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) From 1261fffbf01b25b5c74f1c2be9f92d39769f85b0 Mon Sep 17 00:00:00 2001 From: Mher Kazandjian Date: Mon, 17 Oct 2016 16:03:43 +0200 Subject: [PATCH 3/3] fixed typo --- lib/matplotlib/cbook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/cbook.py b/lib/matplotlib/cbook.py index fb7834b578b4..22e4a8819bc6 100644 --- a/lib/matplotlib/cbook.py +++ b/lib/matplotlib/cbook.py @@ -1280,7 +1280,7 @@ def allpairs(x): class maxdict(dict): """ A dictionary with a maximum size; this doesn't override all the - relevant methods to contain size, just setitem, so use with + relevant methods to constrain the size, just setitem, so use with caution """ def __init__(self, maxsize):