Neuraxio / Neuraxle

The world's cleanest AutoML library ✨ - Do hyperparameter tuning with the right pipeline abstractions to write clean deep learning production pipelines. Let your pipeline steps have hyperparameter spaces. Design steps in your pipeline like components. Compatible with Scikit-Learn, TensorFlow, and most other libraries, frameworks and MLOps environments.
https://www.neuraxle.org/
Apache License 2.0
608 stars 62 forks source link

Feature: Create `_HasAssertsMixin` to do things like `self._assert(1 == 1, error_msg, context, level=None)`. #495

Closed guillaume-chevalier closed 2 years ago

guillaume-chevalier commented 3 years ago
class _HasAssertsMixin:
    def _assert(
            self, truth_value, err_msg, context: ExecutionContext = None, level: ExecutionPhase = ExecutionPhase.TEST
    ):
        if not truth_value:
            self._log_err(err_msg)
        if context is None or level is None or context.execution_phase <= level):
            assert truth_value, err_msg

class MyStep(_HasAssertsMixin, _HasLoggerMixin, BaseStep):

    def _fit_transform_data_container(
            self, data_container: DataContainer, context: ExecutionContext
    ) -> ('BaseStep', DataContainer): 
        self._assert(1 == 1, f"this is in error: {1 == 1}.", context, level=None)
        return self, data_container
guillaume-chevalier commented 3 years ago

Related: #483.