from functools import wraps


def return_original_if_failed(func):
    """
    A helper function that will return the original input
    if the function failed. Useful for xr.Dataset.pipe(function)
    """
    
    @wraps(func)
    def wrapper(ds, **kwargs):
        try:
            ds = func(ds, **kwargs)
        except:
            funcname = func.__name__
            print(f'`{funcname}` failed, returning original input')
        return ds
    return wrapper