Example #1
0
    def handle_fit_transform(self, data_container: DataContainer, context: ExecutionContext) -> (
    'ReversiblePreprocessingWrapper', DataContainer):
        """
        According to the idiom of `(1, 2, reversed(1))`, we do this, in order:

            - `1`. Fit Transform preprocessing step
            - `2`. Fit Transform postprocessing step
            - `reversed(1)`. Inverse transform preprocessing step

        :param data_container: data container to transform
        :type data_container: DataContainer
        :param context: execution context
        :type context: ExecutionContext
        :return: (self, data_container)
        :rtype: (ReversiblePreprocessingWrapper, DataContainer)
        """
        self["preprocessing_step"], data_container = self["preprocessing_step"].handle_fit_transform(data_container,
                                                                                                     context.push(self[
                                                                                                                      "preprocessing_step"]))
        self["postprocessing_step"], data_container = self["postprocessing_step"].handle_fit_transform(data_container,
                                                                                                       context.push(
                                                                                                           self[
                                                                                                               "postprocessing_step"]))

        data_container = self["preprocessing_step"].handle_inverse_transform(data_container,
                                                                             context.push(self["preprocessing_step"]))

        current_ids = self.hash(data_container)
        data_container.set_current_ids(current_ids)

        return self, data_container
Example #2
0
    def _transform_data_container(self, data_container: DataContainer,
                                  context: ExecutionContext) -> DataContainer:
        """
        According to the idiom of `(1, 2, reversed(1))`, we do this, in order:

            - `1`. Transform preprocessing step
            - `2`. Transform postprocessing step
            - `reversed(1)`. Inverse transform preprocessing step

        :param data_container: data container to transform
        :param context: execution context
        :return: data_container
        """
        data_container = self["preprocessing_step"].handle_transform(
            data_container, context.push(self["preprocessing_step"]))
        data_container = self["postprocessing_step"].handle_transform(
            data_container, context.push(self["postprocessing_step"]))

        data_container = self["preprocessing_step"].handle_inverse_transform(
            data_container, context.push(self["preprocessing_step"]))

        current_ids = self.hash(data_container)
        data_container.set_current_ids(current_ids)

        return data_container
Example #3
0
    def handle_fit_transform(self, data_container: DataContainer,
                             context: ExecutionContext):
        """
        Change the shape of the data container.
        and/or
        Apply any side effects based on the data container
        And/or
        Change the execution flow of the pipeline
        """

        current_ids = self.hash(data_container)
        data_container.set_current_ids(current_ids)

        return self, data_container
Example #4
0
    def _create_expanded_data_container(
            self, data_container: DataContainer) -> ExpandedDataContainer:
        """
        Create expanded data container.

        :param data_container: data container to expand
        :type data_container: DataContainer
        :return: expanded data container
        :rtype: ExpandedDataContainer
        """
        current_ids = self.hash(data_container)
        data_container.set_current_ids(current_ids)

        expanded_data_container = ExpandedDataContainer.create_from(
            data_container)

        return expanded_data_container
Example #5
0
    def handle_fit(self, data_container: DataContainer, context: ExecutionContext) -> 'ReversiblePreprocessingWrapper':
        """
        Handle fit by fitting preprocessing step, and postprocessing step.

        :param data_container: data container to fit on
        :type data_container: DataContainer
        :param context: execution context
        :type context: ExecutionContext
        :return: self, data_container
        :rtype: (ReversiblePreprocessingWrapper, DataContainer)
        """
        self["preprocessing_step"], data_container = \
            self["preprocessing_step"].handle_fit_transform(data_container, context.push(self["preprocessing_step"]))
        self["postprocessing_step"] = \
            self["postprocessing_step"].handle_fit(data_container, context.push(self["postprocessing_step"]))

        current_ids = self.hash(data_container)
        data_container.set_current_ids(current_ids)

        return self
Example #6
0
    def handle_transform(self, data_containers,
                         context: ExecutionContext) -> DataContainer:
        """
        Handle transform.

        :param data_containers: the data container to join
        :param context: execution context
        :return: transformed data container
        """
        data_inputs = self.transform(
            [dc.data_inputs for dc in data_containers])
        data_container = DataContainer(
            current_ids=data_containers[-1].current_ids,
            data_inputs=data_inputs,
            expected_outputs=data_containers[-1].expected_outputs)
        data_container.set_data_inputs(data_inputs)

        current_ids = self.hash(data_container)
        data_container.set_current_ids(current_ids)

        return data_container