def _add_external_data(self, chunk, ext_dataset, external_features, horizon=None): ''' Currently coming from 820 (for all the meters I do consider) Paramters --------- chunk: pd.DataFrame, pd.DatetimeIndex The input which have to be augmented ext_dataset: nilmtk.Dataset The Dataset, where the external Data can be found. horizon: nilmtk.Timedelta The timeframe in the future for which external data shall be retrieved. This will be outside the chunk area sothat it is extended. Necessary for forecast with external data included. external_features: [indixes,... ] The indexes which shall be retrieved. Returns ------- chunk: pd.DataFrame The input chunk extended by the features given in external_features. ''' if not horizon is None and not type(horizon) is pd.Timedelta: raise Exception("Horizon has to be a DatetimeDelta") if not external_features is None and not type( external_features) is list: external_features = [external_features] # Sothat index is also supported if type(chunk) is pd.DatetimeIndex: chunk = pd.DataFrame(index=chunk) extData = None if len(external_features) > 0: section = TimeFrame(start=chunk.index[0], end=chunk.index[-1]) if not horizon is None: section.end = section.end + horizon extData = ext_dataset.get_data_for_group('820', section, 60 * 15, external_features)[1:] return pd.concat([chunk, extData], axis=1)
def test_date_setting(self): TimeFrame() TimeFrame("2012-01-01", "2013-01-01") # test identical start and end dates with self.assertRaises(ValueError): TimeFrame("2012-01-01", "2012-01-01") TimeFrame(start="2011-01-01") TimeFrame(end="2011-01-01") # test end date after start date with self.assertRaises(ValueError): TimeFrame("2012-01-01", "2011-01-01") tf = TimeFrame() tf.end = "2011-01-01" tf.start = "2010-01-01" with self.assertRaises(ValueError): tf.start = "2012-01-01"