flotilla.util module

General use utilities

exception flotilla.util.AssertionError(*args, **kwargs)[source]

Bases: exceptions.StandardError

Assertion failed.

exception flotilla.util.TimeoutError[source]

Bases: exceptions.Exception

From: http://stackoverflow.com/questions/2281850/timeout-function-if-it-takes-too-long-to-finish

flotilla.util.add_package_data_resource(self, file_name, data_df, toplevel_package_dir, file_write_mode='tsv')[source]
flotilla.util.as_numpy(x)[source]

Given either a pandas dataframe or a numpy array, always return a numpy array.

class flotilla.util.cached_property(ttl=0)[source]

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

flotilla.util.dict_to_str(dic)[source]

join dictionary study_data into a string with that study_data

flotilla.util.get_loading_method(self, file_name)[source]

loading_methods for loading from file

flotilla.util.install_development_package(package_location)[source]
flotilla.util.load_csv(file_name, **kwargs)[source]
flotilla.util.load_gzip_pickle_df(file_name)[source]
flotilla.util.load_json(filename, **kwargs)[source]
Parameters:

filename : str

Name of the json file toread

compression : str

Not used, only for compatibility with other load functions

flotilla.util.load_pickle_df(file_name)[source]
flotilla.util.load_tsv(file_name, **kwargs)[source]
flotilla.util.memoize(obj)[source]

‘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

do_not_memoize : bool
IF this is a keyword argument (kwarg) in the function, and it is true, then just evaluate the function and don’t memoize it.
flotilla.util.natural_sort(l)[source]

From http://stackoverflow.com/a/4836734

flotilla.util.serve_ipython()[source]
flotilla.util.timeout(seconds=10, error_message='Timer expired')[source]
flotilla.util.timestamp()[source]
flotilla.util.to_base_file_tuple(tup)[source]

for making new packages, auto-loadable data!

flotilla.util.validate_params(self)[source]

make sure that all necessary attributes are present

flotilla.util.write_csv(df, file_name)[source]
flotilla.util.write_gzip_pickle_df(df, file_name)[source]
flotilla.util.write_pickle_df(df, file_name)[source]
flotilla.util.write_tsv(df, file_name)[source]
Olga B. Botvinnik is funded by the NDSEG fellowship and is a NumFOCUS John Hunter Technology Fellow.
Michael T. Lovci was partially funded by a fellowship from Genentech.
Partially funded by NIH grants NS075449 and HG004659 and CIRM grants RB4-06045 and TR3-05676 to Gene Yeo.