General use utilities
Bases: exceptions.StandardError
Assertion failed.
Bases: exceptions.Exception
From: http://stackoverflow.com/questions/2281850/timeout-function-if-it-takes-too-long-to-finish
Given either a pandas dataframe or a numpy array, always return a numpy array.
Bases: object
Decorator for read-only properties evaluated only once within TTL period.
It can be used to created a cached property like this:
import random
# the class containing the property must be a new-style class
class MyClass(object):
# create property whose value is cached for ten minutes
@cached_property(ttl=600)
def randint(self):
# will only be evaluated every 10 min. at maximum.
return random.randint(0, 100)
The value is cached in the ‘_cache’ attribute of the object instance that has the property getter method wrapped by this decorator. The ‘_cache’ attribute value is a dictionary which has a key for every property of the object which is wrapped by this decorator. Each entry in the cache is created only when the property is accessed for the first time and is a two-element tuple with the last computed property value and the last time it was updated in seconds since the epoch.
The default time-to-live (TTL) is 300 seconds (5 minutes). Set the TTL to zero for the cached value to never expire.
To expire a cached property value manually just do:
del instance._cache[<property name>]
Stolen from: https://wiki.python.org/moin/PythonDecoratorLibrary#Cached_Properties
join dictionary study_data into a string with that study_data
Parameters: | filename : str
compression : str
|
---|
‘Memoize’ aka remember the output from a function and return that, rather than recalculating
Stolen from: https://wiki.python.org/moin/PythonDecoratorLibrary#CA-237e205c0d5bd1459c3663a3feb7f78236085e0a_1