store

Store functionality for the CLI

Notes

A store is an abstraction for a folder in the user’s local data directory which pertains to a specific dataset that comprises of RNG output. The store can subsequently store test results and report markup for said results.

exception coinflip.store.DataParsingError[source]

Base class for parsing-related errors

coinflip.store.parse_data(data_file, dtype_str=None) → pandas.core.series.Series[source]

Reads file containing data into a pandas Series

Reads from file containing RNG output and produces a representitive pandas Series. The appropiate dtype is inferred from the data itself, or optionally from the supplied dtype_str.

Parameters:
  • data_file (file-like object) – File containing RNG output
  • dtype_str (str, optional) – String representation of desired dtype. If not supplied, it is inferred from the data.
Returns:

Series – A pandas Series which represents the data

Raises:
  • TypeNotRecognizedError – If supplied dtype_str does not recognise a dtype
  • MultipleColumnsError – If inputted data contains multiple values per line
  • NonBinarySequenceError – If sequence does not contain only 2 values

See also

pandas.read_csv()
The pandas method for reading data_file
store_data()
Calls this method, and handles subsequent storage of data
exception coinflip.store.StoreError(store_name)[source]

Base class for store-related errors

coinflip.store.init_store(name=None, overwrite=False)[source]

Creates store in local data

A name supplied or generated is used to initialise a store. If supplied, the name is sanitised to remove invalid characters for filepaths. If generated, the name will be a timestamp of initialisation.

Parameters:
  • name (str, optional) – Desired name of the store, which will be sanitised. If not supplied, a name is generated automatically.
  • overwrite (boolean, default False) – If a name conflicts with an existing store, this decides whether to overwrite it.
Returns:

  • store_name (str) – Internal name of the initialised store
  • store_path (Path) – Path of the initialised store

Raises:
  • NameConflictError – If attempts at generating a unique name fails
  • StoreExistsError – If a store of the same name exists already (and overwrite is set to False)
  • NonBinarySequenceError – If sequence does not contain only 2 values

See also

store_data()
Parses data and calls this method, to then save data in store
coinflip.store.store_data(data_file, name=None, dtype_str=None, overwrite=False)[source]

Load and parse RNG output, serialised to a local data directory

Reads from file containing RNG output and produces a representitive pandas Series. The appropiate dtype is inferred from the data itself, or optionally from the supplied dtype_str.

A name supplied or generated is used to initialise a store. If supplied, the name is sanitised to remove invalid characters for filepaths. If generated, the name will be a timestamp of initialisation.

The representive Series is serialised using Python’s pickle module, saved in the initialised store.

The store’s name is also written to a file in the user data directory, to be accessed later when identifying the last initialised store.

Parameters:
  • data_file (file-like object) – File containing RNG output
  • name (str, optional) – Desired name of the store, which will be sanitised. If not supplied, a name is generated automatically.
  • dtype_str (str, optional) – String representation of desired dtype. If not supplied, it is inferred from the data.
  • overwrite (bool, default False) – If a name conflicts with an existing store, this decides whether to overwrite it.
Raises:
  • TypeNotRecognizedError – If supplied dtype_str does not recognise a dtype
  • MultipleColumnsError – If inputted data contains multiple values per line
  • NameConflictError – If attempts at generating a unique name fails
  • StoreExistsError – If a store of the same name exists already (and overwrite is set to False)

See also

parse_data()
Loads and parses data_file
init_store()
Initialises the store
find_latest_store()
Accesses the name of the last initialised store
exception coinflip.store.NoLatestStoreRecordedError[source]

Error for when latest store cannot be identified

coinflip.store.find_latest_store() → str[source]

Find out the last initialised store

A file is kept in the root user data directory to record the last initialised store’s name, which this method reads to identify the store.

Returns:store_name (str) – Name of the last initialised store
Raises:NoLatestStoreRecordedError – When no last initialised store is found
coinflip.store.get_data(store_name) → pandas.core.series.Series[source]

Access data of a store

Parameters:

store_name (str) – Name of the store

Returns:

Series – A pandas Series which represents the data

Raises:
  • StoreNotFoundError – If requested store does not exist
  • DataNotFoundError – If requested store has no data
coinflip.store.drop(store_name)[source]

Remove store from local data

Parameters:store_name (str) – Name of store to remove
coinflip.store.list_stores()[source]

List all stores in local data

coinflip.store.store_result(store_name, randtest_name, result: coinflip.randtests._result.TestResult)[source]

Store result of a statistical test

Parameters:
  • store_name (str) – Name of store to save result in
  • randtest_name (str) – Name of statistical test the result came from
  • result (TestResult) – Result of the statistical test

See also

store_results()
Store multiple results from multiple statistical tests
coinflip.store.store_results(store_name, results_dict: Dict[str, coinflip.randtests._result.TestResult])[source]

Store results of multiple statistical tests

Parameters:
  • store_name (str) – Name of store to save result in
  • results_dict (Dict[str, TestResult]) – Mapping of statistical tests to their respective results

See also

store_result()
Store a single results from a single statistical test
coinflip.store.open_results(store_name)[source]

Context manager to read/write results of a store

Parameters:store_name (str) – Name of store to access results in
Yields:results (Dict[str, TestResult]) – Previously stored results of statistical tests
Raises:StoreNotFoundError – If requested store does not exist