Module trase.tools.etl.context
Classes
class Context (year: int,
data_directory: str,
extra: dict | None = <factory>,
pre_extracted_data: dict | None = None,
skip_cache: bool | None = None)-
Simple container for useful information about a model.
This object can be passed around the preparation script, run script, or elsewhere, to provide global variables for a model.
If the variable is really a hard-coded constant, consider putting it in a file like
constants.pyinstead.Args
year- the year for which the model is related to. This will be used, for
example, in conjunction with the
data_directoryargument to determine where to store input and output data for the model. data_directory- path to a directory on the local file system which should be used to store input and output data for the model.
extra:optional- a dictionary of extra metadata for the model, such as a model parameter.
pre_extracted_data:optional- dataframes to pass to the preparation files.
skip_cache:optional- if
True, do not use the cache of files previously downloaded from S3: download them again instead. IfFalse, always use the cache. IfNone(the default) then the configuration settingTRASE_ETL__SKIP_CACHEdecides, which itself defaults toFalse.
Instance variables
var data_directory : strvar extra : dict | Nonevar pre_extracted_data : dict | Noneprop should_skip_cache : bool-
Whether files should be downloaded from S3 without consulting the cache.
This resolves the
skip_cacheargument against the Trase configuration: see the documentation of that argument. var skip_cache : bool | Nonevar year : int
Methods
def replace(self, **changes)-
Return a copy of the instance except with some fields overwritten.
This method is identical to
dataclasses.replaceexcept that it will handle overwriting only a subset of keys ofextra:# we have two pieces of extra information: "complex" and "percent" old = Context(2013, "/tmp/", extra=dict(complex=True, percent=10)) # we alter percent only new = old.replace(extra=dict(percent=50)) # percent has updated, but complex is unchanged new.extra["complex"] # True new.extra["percent"] # 50If you do not wish to have this behaviour then simply use
dataclasses.replace