From d9e5e3768a6e4a1c13f4dff55647b9d515cfc701 Mon Sep 17 00:00:00 2001 From: alexbrillant Date: Fri, 3 Apr 2020 23:20:05 -0400 Subject: [PATCH] Fix Issue #236 --- neuraxle/base.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/neuraxle/base.py b/neuraxle/base.py index 3b24ed4d..5c2b34a6 100644 --- a/neuraxle/base.py +++ b/neuraxle/base.py @@ -3193,6 +3193,13 @@ class TransformHandlerOnlyMixin(NonFittableMixin): @abstractmethod def _transform_data_container(self, data_container: DataContainer, context: ExecutionContext) -> DataContainer: + """ + Transform data container with the given execution context. + + :param data_container: data container + :param context: execution context + :return: transformed data container + """ raise NotImplementedError('Must implement _transform_data_container in {0}'.format(self.name)) def transform(self, data_inputs) -> 'HandleOnlyMixin': @@ -3269,7 +3276,13 @@ def __init__(self, cache_folder=None): cache_folder = DEFAULT_CACHE_FOLDER self.cache_folder = cache_folder - def transform(self, data_inputs): + def transform(self, data_inputs) -> Iterable: + """ + Using :func:`~neuraxle.base.BaseStep.handle_transform`, transform data inputs. + + :param data_inputs: data inputs + :return: outputs + """ execution_context = ExecutionContext(self.cache_folder, execution_mode=ExecutionMode.TRANSFORM) context, data_container = self._encapsulate_data( data_inputs, expected_outputs=None, execution_mode=ExecutionMode.TRANSFORM) @@ -3279,18 +3292,38 @@ def transform(self, data_inputs): return data_container.data_inputs def fit(self, data_inputs, expected_outputs=None) -> 'HandleOnlyMixin': + """ + Using :func:`~neuraxle.base.BaseStep.handle_fit`, fit step with the given data inputs, and expected outputs. + + :param data_inputs: data inputs + :return: fitted self + """ context, data_container = self._encapsulate_data(data_inputs, expected_outputs, ExecutionMode.FIT) new_self = self.handle_fit(data_container, context) return new_self def fit_transform(self, data_inputs, expected_outputs=None) -> Tuple['HandleOnlyMixin', Iterable]: + """ + Using :func:`~neuraxle.base.BaseStep.handle_fit_transform`, fit and transform step with the given data inputs, and expected outputs. + + :param data_inputs: data inputs + :return: fitted self, outputs + """ context, data_container = self._encapsulate_data(data_inputs, expected_outputs, ExecutionMode.FIT_TRANSFORM) new_self, data_container = self.handle_fit_transform(data_container, context) return new_self, data_container.data_inputs - def _encapsulate_data(self, data_inputs, expected_outputs=None, execution_mode=None): + def _encapsulate_data(self, data_inputs, expected_outputs=None, execution_mode=None) -> Tuple[ExecutionContext, DataContainer]: + """ + Encapsulate data with :class:`~neuraxle.data_container.DataContainer`. + + :param data_inputs: data inputs + :param expected_outputs: expected outputs + :param execution_mode: execution mode + :return: execution context, data container + """ data_container = DataContainer(data_inputs=data_inputs, expected_outputs=expected_outputs) context = ExecutionContext(root=self.cache_folder, execution_mode=execution_mode) @@ -3331,11 +3364,22 @@ class EvaluableStepMixin: def get_score(self): raise NotImplementedError() + class FullDumpLoader(Identity): """ Identity step that can load the full dump of a pipeline step. Used by :func:`~neuraxle.base.BaseStep.load`. + Usage example: + + .. code-block:: python + + saved_step = FullDumpLoader( + name=path, + stripped_saver=self.stripped_saver + ).load(context_for_loading, True) + + .. seealso:: :class:`ExecutionContext` :class:`BaseStep`,