@@ -269,13 +269,13 @@ def is_missing(self, s):
269
269
270
270
271
271
class tostr (converter ):
272
- ' convert to string or None'
272
+ """ convert to string or None"""
273
273
def __init__ (self , missing = 'Null' , missingval = '' ):
274
274
converter .__init__ (self , missing = missing , missingval = missingval )
275
275
276
276
277
277
class todatetime (converter ):
278
- ' convert to a datetime or None'
278
+ """ convert to a datetime or None"""
279
279
def __init__ (self , fmt = '%Y-%m-%d' , missing = 'Null' , missingval = None ):
280
280
'use a :func:`time.strptime` format string for conversion'
281
281
converter .__init__ (self , missing , missingval )
@@ -289,7 +289,7 @@ def __call__(self, s):
289
289
290
290
291
291
class todate (converter ):
292
- ' convert to a date or None'
292
+ """ convert to a date or None"""
293
293
def __init__ (self , fmt = '%Y-%m-
10000
%d' , missing = 'Null' , missingval = None ):
294
294
'use a :func:`time.strptime` format string for conversion'
295
295
converter .__init__ (self , missing , missingval )
@@ -303,7 +303,7 @@ def __call__(self, s):
303
303
304
304
305
305
class tofloat (converter ):
306
- ' convert to a float or None'
306
+ """ convert to a float or None"""
307
307
def __init__ (self , missing = 'Null' , missingval = None ):
308
308
converter .__init__ (self , missing )
309
309
self .missingval = missingval
@@ -315,7 +315,7 @@ def __call__(self, s):
315
315
316
316
317
317
class toint (converter ):
318
- ' convert to an int or None'
318
+ """ convert to an int or None"""
319
319
def __init__ (self , missing = 'Null' , missingval = None ):
320
320
converter .__init__ (self , missing )
321
321
@@ -326,7 +326,7 @@ def __call__(self, s):
326
326
327
327
328
328
class _BoundMethodProxy (object ):
329
- '''
329
+ """
330
330
Our own proxy object which enables weak references to bound and unbound
331
331
methods and arbitrary callables. Pulls information about the function,
332
332
class, and instance out of a bound method. Stores a weak reference to the
@@ -337,7 +337,7 @@ class _BoundMethodProxy(object):
337
337
@license: The BSD License
338
338
339
339
Minor bugfixes by Michael Droettboom
340
- '''
340
+ """
341
341
def __init__ (self , cb ):
342
342
self ._hash = hash (cb )
343
343
self ._destroy_callbacks = []
@@ -386,13 +386,13 @@ def __setstate__(self, statedict):
386
386
self .inst = ref (inst )
387
387
388
388
def __call__ (self , * args , ** kwargs ):
389
- '''
389
+ """
390
390
Proxy for a call to the weak referenced object. Take
391
391
arbitrary params to pass to the callable.
392
392
393
393
Raises `ReferenceError`: When the weak reference refers to
394
394
a dead object
395
- '''
395
+ """
396
396
if self .inst is not None and self .inst () is None :
397
397
raise ReferenceError
398
398
elif self .inst is not None :
@@ -421,9 +421,9 @@ def __eq__(self, other):
421
421
return False
422
422
423
423
def __ne__ (self , other ):
424
- '''
424
+ """
425
425
Inverse of __eq__.
426
- '''
426
+ """
427
427
return not self .__eq__ (other )
428
428
429
429
def __hash__ (self ):
@@ -626,7 +626,7 @@ def local_over_kwdict(local_var, kwargs, *keys):
626
626
627
627
628
628
def strip_math (s ):
629
- ' remove latex formatting from mathtext'
629
+ """ remove latex formatting from mathtext"""
630
630
remove = (r'\mathdefault' , r'\rm' , r'\cal' , r'\tt' , r'\it' , '\\ ' , '{' , '}' )
631
631
s = s [1 :- 1 ]
632
632
for r in remove :
@@ -658,12 +658,12 @@ def __repr__(self):
658
658
659
659
660
660
def unique (x ):
661
- ' Return a list of unique elements of *x*'
661
+ """ Return a list of unique elements of *x*"""
662
662
return list (six .iterkeys (dict ([(val , 1 ) for val in x ])))
663
663
664
664
665
665
def iterable (obj ):
666
- ' return true if *obj* is iterable'
666
+ """ return true if *obj* is iterable"""
667
667
try :
668
668
iter (obj )
669
669
except TypeError :
@@ -672,7 +672,7 @@ def iterable(obj):
672
672
673
673
674
674
def is_string_like (obj ):
675
- ' Return True if *obj* looks like a string'
675
+ """ Return True if *obj* looks like a string"""
676
676
if isinstance (obj , six .string_types ):
677
677
return True
678
678
# numpy strings are subclass of str, ma strings are not
@@ -689,9 +689,7 @@ def is_string_like(obj):
689
689
690
690
691
691
def is_sequence_of_strings (obj ):
692
- """
693
- Returns true if *obj* is iterable and contains strings
694
- """
692
+ """Returns true if *obj* is iterable and contains strings"""
695
693
if not iterable (obj ):
696
694
return False
697
695
if is_string_like (obj ) and not isinstance (obj , np .ndarray ):
@@ -707,9 +705,7 @@ def is_sequence_of_strings(obj):
707
705
708
706
709
707
def is_hashable (obj ):
710
- """
711
- Returns true if *obj* can be hashed
712
- """
708
+ """Returns true if *obj* can be hashed"""
713
709
try :
714
710
hash (obj )
715
711
except TypeError :
@@ -718,7 +714,7 @@ def is_hashable(obj):
718
714
719
715
720
716
def is_writable_file_like (obj ):
721
- ' return true if *obj* looks like a file object with a *write* method'
717
+ """ return true if *obj* looks like a file object with a *write* method"""
722
718
return hasattr (obj , 'write' ) and six .callable (obj .write )
723
719
724
720
@@ -736,12 +732,12 @@ def file_requires_unicode(x):
736
732
737
733
738
734
def is_scalar (obj ):
739
- ' return true if *obj* is not string like and is not iterable'
735
+ """ return true if *obj* is not string like and is not iterable"""
740
736
return not is_string_like (obj ) and not iterable (obj )
741
737
742
738
743
739
def is_numlike (obj ):
744
- ' return true if *obj* looks like a number'
740
+ """ return true if *obj* looks like a number"""
745
741
try :
746
742
obj + 1
747
743
except :
@@ -1034,7 +1030,7 @@ def __call__(self, path):
1034
1030
1035
1031
1036
1032
def dict_delall (d , keys ):
1037
- ' delete all of the *keys* from the :class:`dict` *d*'
1033
+ """ delete all of the *keys* from the :class:`dict` *d*"""
1038
1034
for key in keys :
1039
1035
try :
1040
1036
del d [key ]
@@ -1084,17 +1080,17 @@ def get_split_ind(seq, N):
1084
1080
.
1085
1081
"""
1086
1082
1087
- sLen = 0
1083
+ s_len = 0
1088
1084
# todo: use Alex's xrange pattern from the cbook for efficiency
1089
1085
for (word , ind ) in zip (seq , xrange (len (seq ))):
1090
- sLen += len (word ) + 1 # +1 to account for the len(' ')
1091
- if sLen >= N :
1086
+ s_len += len (word ) + 1 # +1 to account for the len(' ')
1087
+ if s_len >= N :
1092
1088
return ind
1093
1089
return len (seq )
1094
1090
1095
1091
1096
1092
def wrap (prefix , text , cols ):
1097
- ' wrap *text* with *prefix* at length *cols*'
1093
+ """ wrap *text* with *prefix* at length *cols*"""
1098
1094
pad = ' ' * len (prefix .expandtabs ())
1099
1095
available = cols - len (pad )
1100
1096
@@ -1284,7 +1280,7 @@ def allpairs(x):
1284
1280
class maxdict (dict ):
1285
1281
"""
1286
1282
A dictionary with a maximum size; this doesn't override all the
1287
- relevant methods to contrain size, just setitem, so use with
1283
+ relevant methods to contain size, just setitem, so use with
1288
1284
caution
1289
1285
"""
1290
1286
def __init__ (self , maxsize ):
@@ -1313,7 +1309,7 @@ def __init__(self, default=None):
1313
1309
self ._default = default
1314
1310
1315
1311
def __call__ (self ):
1316
- ' return the current element, or None'
1312
+ """ return the current element, or None"""
1317
1313
if not len (self ._elements ):
1318
1314
return self ._default
1319
1315
else :
@@ -1326,14 +1322,14 @@ def __getitem__(self, ind):
1326
1322
return self ._elements .__getitem__ (ind )
1327
1323
1328
1324
def forward (self ):
1329
- ' move the position forward and return the current element'
1330
- N = len (self ._elements )
1331
- if self ._pos < N - 1 :
1325
+ """ move the position forward and return the current element"""
1326
+ n = len (self ._elements )
1327
+ if self ._pos < n - 1 :
1332
1328
self ._pos += 1
1333
1329
return self ()
1334
1330
1335
1331
def back (self ):
1336
- ' move the position back and return the current element'
1332
+ """ move the position back and return the current element"""
1337
1333
if self ._pos > 0 :
1338
1334
self ._pos -= 1
1339
1335
return self ()
@@ -1349,7 +1345,7 @@ def push(self, o):
1349
1345
return self ()
1350
1346
1351
1347
def home (self ):
1352
- ' push the first element onto the top of the stack'
1348
+ """ push the first element onto the top of the stack"""
1353
1349
if not len (self ._elements ):
1354
1350
return
1355
1351
self .push (self ._elements [0 ])
@@ -1359,7 +1355,7 @@ def empty(self):
1359
1355
return len (self ._elements ) == 0
1360
1356
1361
1357
def clear (self ):
1362
- ' empty the stack'
1358
+ """ empty the stack"""
1363
1359
self ._pos = - 1
1364
1360
self ._elements = []
1365
1361
@@ -1411,7 +1407,7 @@ def finddir(o, match, case=False):
1411
1407
1412
1408
1413
1409
def reverse_dict (d ):
1414
- ' reverse the dictionary -- may lose data if values are not unique!'
1410
+ """ reverse the dictionary -- may lose data if values are not unique!"""
1415
1411
return dict ([(v , k ) for k , v in six .iteritems (d )])
1416
1412
1417
1413
@@ -1424,7 +1420,7 @@ def restrict_dict(d, keys):
1424
1420
1425
1421
1426
1422
def report_memory (i = 0 ): # argument may go away
1427
- ' return the memory consumed by process'
1423
+ """ return the memory consumed by process"""
1428
1424
from matplotlib .compat .subprocess import Popen , PIPE
1429
1425
pid = os .getpid ()
1430
1426
if sys .platform == 'sunos5' :
@@ -1473,7 +1469,7 @@ def report_memory(i=0): # argument may go away
1473
1469
1474
1470
1475
1471
def safezip (* args ):
1476
- ' make sure *args* are equal len before zipping'
1472
+ """ make sure *args* are equal len before zipping"""
1477
1473
Nx = len (args [0 ])
1478
1474
for i , arg in enumerate (args [1 :]):
1479
1475
if len (arg ) != Nx :
@@ -1482,7 +1478,7 @@ def safezip(*args):
1482
1478
1483
1479
1484
1480
def issubclass_safe (x , klass ):
1485
- ' return issubclass(x, klass) and return False on a TypeError'
1481
+ """ return issubclass(x, klass) and return False on a TypeError"""
1486
1482
1487
1483
try :
1488
1484
return issubclass (x , klass )
@@ -2198,7 +2194,7 @@ def _reshape_2D(X):
2198
2194
2199
2195
2200
2196
def violin_stats (X , method , points = 100 ):
2201
- '''
2197
+ """
2202
2198
Returns a list of dictionaries of data which can be used to draw a series
2203
2199
of violin plots. See the `Returns` section below to view the required keys
2204
2200
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):
2235
2231
- median: The median value for this column of data.
2236
2232
- min: The minimum value for this column of data.
2237
2233
- max: The maximum value for this column of data.
2238
- '''
2234
+ """
2239
2235
2240
2236
# List of dictionaries describing each of the violins.
2241
2237
vpstats = []
@@ -2318,7 +2314,7 @@ def _step_validation(x, *args):
2318
2314
args = tuple (np .asanyarray (y ) for y in args )
2319
2315
x = np .asanyarray (x )
2320
2316
if x .ndim != 1 :
2321
- raise ValueError ("x must be 1 dimenional " )
2317
+ raise ValueError ("x must be 1 dimensional " )
2322
2318
if len (args ) == 0 :
2323
2319
raise ValueError ("At least one Y value must be passed" )
2324
2320
@@ -2501,8 +2497,7 @@ def safe_first_element(obj):
2501
2497
2502
2498
2503
2499
def sanitize_sequence (data ):
2504
- """Converts dictview object to list
2505
- """
2500
+ """Converts dictview object to list"""
2506
2501
if six .PY3 and isinstance (data , collections .abc .MappingView ):
2507
2502
return list (data )
2508
2503
return data
0 commit comments