def test_transform(self): input_dict = {'input_data': None} step = Step(self.module_mock, {"x": self.step_mock}, None) step._fit(input_dict, {}) step._transform(input_dict) self.module_mock.transform.assert_called_once_with(**input_dict)
def test_input_finished(self): input_dict = {'input_data': None} step = Step(self.module_mock, self.step_mock, file_manager=MagicMock()) step._fit(input_dict, {}) self.module_mock.fit.assert_called_once_with(**input_dict)
def create_step(self, module: Base, kwargs: Dict[str, Union[StepInformation, Tuple[StepInformation, ...]]], use_inverse_transform: bool, use_predict_proba: bool, callbacks: List[Union[BaseCallback, Callable[[Dict[str, xr.DataArray]], None]]], condition, batch_size, computation_mode, train_if): """ Creates a appropriate step for the current situation. :param module: The module which should be added to the pipeline :param kwargs: The input steps for the current step :param targets: The target steps for the currrent step :param use_inverse_transform: Should inverse_transform be called instead of transform :param use_predict_proba: Should probabilistic_transform be called instead of transform :param callbacks: Callbacks to use after results are processed. :param condition: A function returning True or False which indicates if the step should be performed :param batch_size: The size of the past time range which should be used for relearning the module :param computation_mode: The computation mode of the step :param train_if: A method for determining if the step should be fitted at a specific timestamp. :return: StepInformation """ arguments = inspect.signature(module.transform).parameters.keys() if "kwargs" not in arguments and not isinstance(module, Pipeline): for argument in arguments: if argument not in kwargs.keys(): raise StepCreationException( f"The module {module.name} miss {argument} as input. The module needs {arguments} as input. " f"{kwargs} are given as input." f"Add {argument}=<desired_input> when adding {module.name} to the pipeline.", module) # TODO needs to check that inputs are unambigious -> I.e. check that each input has only one output pipeline = self._check_ins(kwargs) input_steps, target_steps = self._split_input_target_steps( kwargs, pipeline) if isinstance(module, Pipeline): step = PipelineStep(module, input_steps, pipeline.file_manager, targets=target_steps, callbacks=callbacks, computation_mode=computation_mode, condition=condition, batch_size=batch_size, train_if=train_if) elif use_inverse_transform: step = InverseStep(module, input_steps, pipeline.file_manager, targets=target_steps, callbacks=callbacks, computation_mode=computation_mode, condition=condition) elif use_predict_proba: step = ProbablisticStep(module, input_steps, pipeline.file_manager, targets=target_steps, callbacks=callbacks, computation_mode=computation_mode, condition=condition) else: step = Step(module, input_steps, pipeline.file_manager, targets=target_steps, callbacks=callbacks, computation_mode=computation_mode, condition=condition, batch_size=batch_size, train_if=train_if) step_id = pipeline.add( module=step, input_ids=[step.id for step in input_steps.values()], target_ids=[step.id for step in target_steps.values()]) step.id = step_id if len(target_steps) > 1: step.last = False for target in target_steps: r_step = step.get_result_step(target) r_id = pipeline.add(module=step, input_ids=[step_id]) r_step.id = r_id return StepInformation(step, pipeline)