CompositeDataSource#

class fourinsight.engineroom.utils.CompositeDataSource(index_source)[source]#

Handles data from a sequence of data sources.

During download, the class will switch between different data sources based on the index.

Parameters:

index_source (list-like) – Sequence of (index, source) tuples. The index value determines which index a source is valid from. The source will then be valid until the next item in the sequence (see Example). If a source is set to None, empty data will be returned for that period.

Examples

This example shows how to set up a composite of three data sources. During data download, data is retrieved from source_a between ‘2020-01-01 00:00’ and ‘2020-01-02 00:00’, from source_b between ‘2020-01-02 00:00’ and ‘2020-01-03 00:00’, and from source_c between ‘2020-01-03 00:00’ and the ‘end’.

>>> index_source = [
        ('2020-01-01 00:00', source_a),
        ('2020-01-02 00:00', source_b),
        ('2020-01-03 00:00', source_c),
    ]
>>> source = CompositeDataSource(index_source)
>>> data = source.get('2020-01-01 00:00', '2020-01-05 00:00')
get(start, end, refresh_cache=False)[source]#

Get data from source.

Parameters:
  • start – Start index of the data. Will be passed on to the get() method of each individual data source.

  • end – End index of the data. Will be passed on to the get() method of each individual data source.

  • refresh_cache (bool) – Refresh cache if True.

Returns:

Source data.

Return type:

pandas.DataFrame

iter(start, end, index_mode='start', refresh_cache=False)[source]#

Iterate over source data as (index, data) pairs.

Parameters:
  • start (array-like) – Sequence of start indexes.

  • end (array-like) – Sequence of end indexes.

  • index_mode (str, optional) – How to index/label the data. Must be ‘start’, ‘end’ or ‘mid’. If ‘start’, start is used as index. If ‘end’, end is used as index. If ‘mid’, the index is set to start + (end - start) / 2.0. Then, the start and end objects must be of such type that this operation is possible.

Yields:
  • index (label) – The index/label.

  • data (pandas.DataFrame) – The source data.

See also

fourinsight.engineroom.utils.iter_index

Convenience functions for generating ‘start’ and ‘end’ index lists.

property labels#

Data source labels.