tabs package¶
Submodules¶
tabs.tables module¶
Table base classes for defning new tables
-
class
tabs.tables.
BaseTableABC
(*args, **kwargs)[source]¶ Bases:
object
Abstract Base class for minimum table import
-
classmethod
dep
()¶ dep is an alias of dependencies
-
classmethod
dependencies
()[source]¶ Returns a list of all dependent tables, in the order they are defined.
Add new dependencies for source and every post proecssor like this:
source.dependencies = [PersonalData] some_post_processor.dependencies = [SomeOtherTable, AnotherTable]
some_post_processor.dependencies needs to be placed after some_post_processor is defined.
-
classmethod
describe
(full=False)[source]¶ - Prints a description of the table based on the provided
- documentation and post processors.
Parameters: full (bool) – Include post processors in the printed description.
-
get_cached_filename
(filename, extention, settings_list=None)[source]¶ Creates a filename with md5 cache string based on settings list
Parameters: - filename (str) – the filename without extention
- extention (str) – the file extention without dot. (i.e. ‘pkl’)
- settings_list (dict|list) – the settings list as list (optional) NB! The dictionaries have to be sorted or hash id will change arbitrarely.
-
classmethod
-
class
tabs.tables.
Table
(*args, **kwargs)[source]¶ Bases:
tabs.tables.BaseTableABC
MetaClass for defining tables.
Attention! The following methods are required when defining a class the inherits from Table
-
output
(self)[source]¶ Should return the output path for where the finished table should be stored. For example a cache directory. (required, method)
Example
Defining a table:
class UserDataTable(Table): def source(self): return pd.read_csv('/path/to/file') def output(self): return "/path/to/output" def post_processors(self): return [ my_custom_function(), my_second_custom_function(), ]
-
fetch
(rebuild=False, cache=True)[source]¶ Fetches the table and applies all post processors. :param rebuild: Rebuild the table and ignore cache. Default: False :type rebuild: bool :param cache: Cache the finished table for faster future loading.
Default: True
-
output
()[source] Path to the processed table (output path)
-
post_processors
()[source] A list of functions to be applied for post processing
-
read_cache
()[source]¶ Defines how to read table from cache. Should be overwritten if to cache is overwritten
-
source
()[source] Path to the original raw data
-
tabs.tabs module¶
Tables module
-
class
tabs.tabs.
Tabs
(package_path=None, custom_table_classes=None)[source]¶ Bases:
object
Class for loading a list of all defined tables, similar to tabs in a browser.
Parameters: - package_path (str) – Path to package containing defined tables
- custom_table_classes (list(class)) – A list of custom Table metaclasses that should also be recognised and added to the tabs list.
Example
Using tabs for listing tables:
from tabs import Tabs package_path = os.path.dirname(os.path.realpath(__file__)) tabs = Tabs(package_path) tabs.table_list() > Avaiable tables: > Persondata > OtherData
Fetching a defined table:
person_data = tabs('Persondata').fetch()
-
describe_all
(full=False)[source]¶ Prints description information about all tables registered :param full: Also prints description of post processors. :type full: bool
-
find_tabs
(custom_table_classes=None)[source]¶ Finds all classes that are subcalss of Table and loads them into a dictionary named tables.
Module contents¶
Tabs