# Path: mlens/utils/exceptions.py
# class NotFittedError(ValueError, AttributeError):
# 
#     """Error class for an ensemble or estimator that is not fitted yet
# 
#     Raised when some method has been called that expects the instance to be
#     fitted.
#     """
# 
# class LayerSpecificationWarning(UserWarning):
# 
#     """Warning class if layer has been specified in a dubious form.
# 
#     This warning is raised when the input does not look like expected, but
#     is not fatal and a best guess of how to fix it will be made.
#     """
# 
# class LayerSpecificationError(TypeError, ValueError):
# 
#     """Error class for incorrectly specified layers."""
# 
# class ParallelProcessingError(AttributeError, RuntimeError):
# 
#     """Error class for fatal errors related to :class:`ParallelProcessing`.
# 
#     Can be subclassed for more specific error classes.
#     """
# 
# class ParallelProcessingWarning(UserWarning):
# 
#     """Warnings related to methods on :class:`ParallelProcessing`.
# 
#     Can be subclassed for more specific warning classes.
#     """


import warnings
from .exceptions import (NotFittedError, LayerSpecificationWarning,
                         LayerSpecificationError, ParallelProcessingError,
                         ParallelProcessingWarning)
    except TypeError:
        raise TypeError("'%s' does not appear to be an instance of an "
                        "estimator class, but the class itself." % instance)


def assert_valid_pipeline(pipeline):
    """Quick check to ensure the pipeline is an mlens Pipeline"""
    cls = str(pipeline.__class__).split("'")[1].lower()
    if not cls.endswith('pipeline') and not cls.startswith('mlens'):
        raise ValueError("Expect mlens Pipeline instance. Got %r" % pipeline)


def assert_correct_format(estimators, preprocessing):
    """Initial check to assert layer can be constructed."""
    if (preprocessing is None) or (not isinstance(preprocessing, dict)):
        if isinstance(estimators, dict):
            # Either no or uniform preprocessing, estimators should be list
            msg = ("Preprocessing is either 'None' or 'list': 'estimators' "
                   "must be of type 'list'. Got %s.")
            raise LayerSpecificationError(msg % type(estimators))
    else:
        # Check that both estimators and preprocessing are dicts
        if not isinstance(preprocessing, dict):
            msg = ("Unexpected format of 'preprocessing'. Needs to be "
                   " of type 'None' or 'list' or 'dict'. Got %s .")
            raise LayerSpecificationError(msg % type(preprocessing))

        if not isinstance(estimators, dict):
            msg = ("Unexpected format of 'estimators'. Needs to be "
                   "'dict' when preprocessing is 'dict'. Got %s.")

# Path: mlens/utils/exceptions.py
# class NotFittedError(ValueError, AttributeError):
# 
#     """Error class for an ensemble or estimator that is not fitted yet
# 
#     Raised when some method has been called that expects the instance to be
#     fitted.
#     """
# 
# class LayerSpecificationWarning(UserWarning):
# 
#     """Warning class if layer has been specified in a dubious form.
# 
#     This warning is raised when the input does not look like expected, but
#     is not fatal and a best guess of how to fix it will be made.
#     """
# 
# class LayerSpecificationError(TypeError, ValueError):
# 
#     """Error class for incorrectly specified layers."""
# 
# class ParallelProcessingError(AttributeError, RuntimeError):
# 
#     """Error class for fatal errors related to :class:`ParallelProcessing`.
# 
#     Can be subclassed for more specific error classes.
#     """
# 
# class ParallelProcessingWarning(UserWarning):
# 
#     """Warnings related to methods on :class:`ParallelProcessing`.
# 
#     Can be subclassed for more specific warning classes.
#     """


# Path: mlens/utils/checks.py
import warnings
from .exceptions import (NotFittedError, LayerSpecificationWarning,
                         LayerSpecificationError, ParallelProcessingError,
                         ParallelProcessingWarning)

    except TypeError:
        raise TypeError("'%s' does not appear to be an instance of an "
                        "estimator class, but the class itself." % instance)


def assert_valid_pipeline(pipeline):
    """Quick check to ensure the pipeline is an mlens Pipeline"""
    cls = str(pipeline.__class__).split("'")[1].lower()
    if not cls.endswith('pipeline') and not cls.startswith('mlens'):
        raise ValueError("Expect mlens Pipeline instance. Got %r" % pipeline)


def assert_correct_format(estimators, preprocessing):
    """Initial check to assert layer can be constructed."""
    if (preprocessing is None) or (not isinstance(preprocessing, dict)):
        if isinstance(estimators, dict):
            # Either no or uniform preprocessing, estimators should be list
            msg = ("Preprocessing is either 'None' or 'list': 'estimators' "
                   "must be of type 'list'. Got %s.")
            raise LayerSpecificationError(msg % type(estimators))
    else:
        # Check that both estimators and preprocessing are dicts
        if not isinstance(preprocessing, dict):
            msg = ("Unexpected format of 'preprocessing'. Needs to be "
                   " of type 'None' or 'list' or 'dict'. Got %s .")
            raise LayerSpecificationError(msg % type(preprocessing))

        if not isinstance(estimators, dict):
            msg = ("Unexpected format of 'estimators'. Needs to be "
                   "'dict' when preprocessing is 'dict'. Got %s.")

            raise LayerSpecificationError(msg % type(estimators))