def extract_window(series, i, left_size, right_size):
    """A helper function to return indices of the window centered at i."""
    n = series.size
    if i <= left_size:
        window_idx = [0] * (left_size - i) + list(range(0, right_size + i + 1))
    elif i + right_size + 1 > n:
        window_idx = list(range(i - left_size, n)) + [n - 1] * (
            right_size + i + 1 - n
        )
    else:
        window_idx = list(range(i - left_size, i + right_size + 1))
    return window_idx