core.files.cache
- core.files.cache.cache_dataframe(cache_file: Path | str, inputs: Literal['check', 'store', 'ignore'] = 'check')[source]
A decorator that caches the result of a function, which is a pandas DataFrame
- inputs:
“check” [default]: store and check the function inputs “store”: store but don’t check the function inputs “ignore”: ignore the function inputs
- core.files.cache.cache_dataset(cache_file: Path | str, attrs=None, **kwargs)[source]
A decorator that caches the dataset returned by a function in a netcdf file
The attribute dictionary attrs is stored in the file, and verified upon reading.
Other kwargs (ex: chunks) are passed to xr.open_dataset
- core.files.cache.cache_json(cache_file: Path | str, inputs: Literal['check', 'store', 'ignore'] = 'check')[source]
A decorator that caches the result of a function to a json file.
- inputs:
“check” [default]: store and check the function inputs “store”: store but don’t check the function inputs “ignore”: ignore the function inputs
- core.files.cache.cache_pickle(cache_file: Path | str, inputs: Literal['check', 'store', 'ignore']='check', check_out=<function <lambda>>)[source]
A decorator that caches the result of a function to a pickle file.
- inputs:
“check” [default]: store and check the function inputs “store”: store but don’t check the function inputs “ignore”: ignore the function inputs
- core.files.cache.cachefunc(cache_file: Path | str, reader: Callable, writer: Callable, check_in: Callable | None = None, check_out: Callable | None = None, fg_kwargs=None)[source]
A decorator that caches the return of a function in a file, with customizable format
- reader: a function that reads inputs/output from the cache file
reader(filename) -> {‘output’: …, ‘input’: …}
- writer: a function that writes the inputs/output to the cache file
writer(filename, output, input_args, input_kwargs)
- check_in: a custom function to test the equality of the inputs
checker(obj1, obj2) -> bool (defaults to None -> no checking)
- check_out: a custom function to test the equality of the outputs
checker(obj1, obj2) -> bool (defaults to ==)
fg_kwargs: kwargs passed to filegen (ex: lock_timeout=-1)