# Path: mlens/utils/utils.py
# def pickle_save(obj, name):
#     """Utility function for pickling an object"""
#     with open(pickled(name), 'wb') as f:
#         pickle.dump(obj, f)
# 
# def pickle_load(name):
#     """Utility function for loading pickled object"""
#     with open(pickled(name), 'rb') as f:
#         return pickle.load(f)
# 
# def load(file, enforce_filetype=True):
#     """Utility exception handler for loading file"""
#     s, lim = get_ivals()
#     if enforce_filetype:
#         file = pickled(file)
#     try:
#         return pickle_load(file)
#     except (EOFError, OSError, IOError) as exc:
#         msg = str(exc)
#         warnings.warn(
#             "Could not load transformer at %s. Will check every %.1f seconds "
#             "for %i seconds before aborting. " % (file, s, lim),
#             ParallelProcessingWarning)
# 
#         ts = time()
#         while not os.path.exists(file):
#             sleep(s)
#             if time() - ts > lim:
#                 raise ParallelProcessingError(
#                     "Could not load transformer at %s\nDetails:\n%r" %
#                     (dir, msg))
# 
#         return pickle_load(file)
# 
# Path: mlens/utils/exceptions.py
# class MetricWarning(UserWarning):
# 
#     """Warning to notify that scoring do not behave as expected.
# 
#     Raised if scoring fails or if aggregating scores fails.
#     """
# 
# class ParameterChangeWarning(UserWarning):
# 
#     """Warning for different params in blueprint estimator and fitted copy.
# 
#     .. versionadded:: 0.2.2
#     """


import os
import warnings
import numpy as np
from scipy.sparse import issparse
from ..utils import pickle_load, pickle_save, load as _load
from ..utils.exceptions import MetricWarning, ParameterChangeWarning
    # Iterate over flattened parameter collection
    if isinstance(lpar, (list, set, tuple)):
        for p1, p2 in zip(lpar, rpar):
            check_params(p1, p2)

    # --- param check ---
    _pass = True

    if lpar is None or rpar is None:
        # None parameters are liable to be overwritten - ignore
        return _pass

    try:
        if isinstance(lpar, (str, bool)):
            _pass = lpar == rpar

        if isinstance(lpar, (int, float)):
            if np.isnan(lpar):
                _pass = np.isnan(rpar)
            elif np.isinf(lpar):
                _pass = np.isinf(rpar)
            else:
                _pass = lpar == rpar
    except Exception:
        # avoid failing a model because we can't make the check we want
        pass

    if not _pass:
        warnings.warn(
            "Parameter value (%r) has changed since model was fitted (%r)." %

# Path: mlens/utils/utils.py
# def pickle_save(obj, name):
#     """Utility function for pickling an object"""
#     with open(pickled(name), 'wb') as f:
#         pickle.dump(obj, f)
# 
# def pickle_load(name):
#     """Utility function for loading pickled object"""
#     with open(pickled(name), 'rb') as f:
#         return pickle.load(f)
# 
# def load(file, enforce_filetype=True):
#     """Utility exception handler for loading file"""
#     s, lim = get_ivals()
#     if enforce_filetype:
#         file = pickled(file)
#     try:
#         return pickle_load(file)
#     except (EOFError, OSError, IOError) as exc:
#         msg = str(exc)
#         warnings.warn(
#             "Could not load transformer at %s. Will check every %.1f seconds "
#             "for %i seconds before aborting. " % (file, s, lim),
#             ParallelProcessingWarning)
# 
#         ts = time()
#         while not os.path.exists(file):
#             sleep(s)
#             if time() - ts > lim:
#                 raise ParallelProcessingError(
#                     "Could not load transformer at %s\nDetails:\n%r" %
#                     (dir, msg))
# 
#         return pickle_load(file)
# 
# Path: mlens/utils/exceptions.py
# class MetricWarning(UserWarning):
# 
#     """Warning to notify that scoring do not behave as expected.
# 
#     Raised if scoring fails or if aggregating scores fails.
#     """
# 
# class ParameterChangeWarning(UserWarning):
# 
#     """Warning for different params in blueprint estimator and fitted copy.
# 
#     .. versionadded:: 0.2.2
#     """


# Path: mlens/parallel/_base_functions.py
import os
import warnings
import numpy as np
from scipy.sparse import issparse
from ..utils import pickle_load, pickle_save, load as _load
from ..utils.exceptions import MetricWarning, ParameterChangeWarning

    # Iterate over flattened parameter collection
    if isinstance(lpar, (list, set, tuple)):
        for p1, p2 in zip(lpar, rpar):
            check_params(p1, p2)

    # --- param check ---
    _pass = True

    if lpar is None or rpar is None:
        # None parameters are liable to be overwritten - ignore
        return _pass

    try:
        if isinstance(lpar, (str, bool)):
            _pass = lpar == rpar

        if isinstance(lpar, (int, float)):
            if np.isnan(lpar):
                _pass = np.isnan(rpar)
            elif np.isinf(lpar):
                _pass = np.isinf(rpar)
            else:
                _pass = lpar == rpar
    except Exception:
        # avoid failing a model because we can't make the check we want
        pass

    if not _pass:
        warnings.warn(
            "Parameter value (%r) has changed since model was fitted (%r)." %

            (lpar, rpar), ParameterChangeWarning)