def METHOD_NAME(time_val):
    if time_val is None:
        return None
    if isinstance(time_val, timedelta):
        return time_val
    with contextlib.suppress(ValueError, ParserError):
        if isinstance(time_val, str):
            return pd.Timedelta(time_val).to_pytimedelta()
    raise ValueError(
        "'period' must be a pandas-compatible time period string",
        " or Python timedelta.",
    )