def _get_date_columns_selector(available_date_offsets, required_date_offsets):
    """
    Return a numpy "fancy index" which maps one set of matrix columns to
    another. Specifically, it will take a matrix with the "available" date
    columns and transform it to one with the "required" columns.

    If any of the required dates are greater than the latest available date
    then the last available date will be used in its place.

    Example:

    >>> available = {'2019-01': 0, '2019-02': 1, '2019-03': 2}
    >>> required  = {'2019-02': 0, '2019-03': 1, '2019-04': 2}

    >>> index = _get_date_columns_selector(available, required)

    >>> matrix = numpy.array([
    ...   [1, 2, 3],
    ...   [4, 5, 6],
    ... ])

    >>> matrix[index]
    array([[2, 3, 3],
           [5, 6, 6]])
    """
    max_available_date = max(available_date_offsets)
    columns = []
    for date in sorted(required_date_offsets):
        if date > max_available_date:
            date = max_available_date
        columns.append(available_date_offsets[date])
    # We want all rows
    rows = slice(None, None, None)
    return rows, columns