def _raise_or_warn_if_not_fitted(estimator):
    """A context manager to make sure a NotFittedError is raised, if a sub-estimator
    raises the error.
    Otherwise, we raise a warning if the pipeline is not fitted, with the deprecation.
    TODO(0.15): remove this context manager and replace with check_is_fitted.
    """
    try:
        yield
    except NotFittedError as exc:
        raise NotFittedError("Pipeline is not fitted yet.") from exc

    # we only get here if the above didn't raise
    try:
        check_is_fitted(estimator)
    except NotFittedError:
        warnings.warn(
            (
                "This Pipeline instance is not fitted yet. Call 'fit' with "
                "appropriate arguments before using other methods such as transform, "
                "predict, etc. This will raise an error in 0.15 instead of the current "
                "warning."
            ),
            FutureWarning,
        )
A context manager to make sure a NotFittedError is raised, if a sub-estimator
    raises the error.
    Otherwise, we raise a warning if the pipeline is not fitted, with the deprecation.
    TODO(0.15): remove this context manager and replace with check_is_fitted.
    
imblearn/pipeline.py