1 from itertools import chain
2 from logging import getLogger
3 from logging.config import fileConfig
4 from pathlib import Path
9 fileConfig((Path.cwd() / 'config') / 'logging.cfg')
13 def __init__(self, dict_features,
16 self._dict_features = dict_features
19 self._timestep = timestep
20 self._dataframe = None
23 self._features = features
25 self._features = set(chain.from_iterable([tuple(u.keys())
26 for u in [*dict_features.values()]]))
31 while current <= self._end:
32 if current not in self._dict_features:
33 self._dict_features[current] = {feature:np.NaN for feature in self._features}
35 null_dict = {feature:np.NaN for feature in self._features}
36 null_dict.update(self._dict_features[current])
37 self._dict_features[current] = null_dict
38 current += self._timestep
44 return {k: self._dict_features[k] for k in sorted(self._dict_features.keys())}
49 if self._dataframe is None:
50 self._dataframe = pd.DataFrame.from_dict(self.full_dict, orient='index')
51 return self._dataframe
54 def dataframe(self, df):
59 self.dataframe = self.dataframe.fillna(method='ffill')