Repository: quantopian/zipline
File: zipline/lib/adjusted_array.py (Python)

Code before:
    -----
    This method is meant to be used with ``toolz.merge_with`` to merge
    adjustment mappings. In case of a collision ``adjustment_lists`` contains
    two lists, existing adjustments at index 0 and new adjustments at index 1.
    When there are no collisions, ``adjustment_lists`` contains a single list.

    Parameters
    ----------
    adjustment_lists : list[list[Adjustment]]
        List(s) of new and/or existing adjustments for a given index.
    front_idx : int
        Index of list in ``adjustment_lists`` that should be used as baseline
        in case of a collision.
    back_idx : int
        Index of list in ``adjustment_lists`` that should extend baseline list
        in case of a collision.

    Returns
    -------
    adjustments : list[Adjustment]
        List of merged adjustments for a given index.
    """
    if len(adjustment_lists) == 1:
        return list(adjustment_lists[0])
    else:
        new_adjustments = list(adjustment_lists[front_idx])
        new_adjustments.extend(adjustment_lists[back_idx])
        return new_adjustments


_merge_methods = {
    'append': partial(_merge_simple, front_idx=0, back_idx=1),
    'prepend': partial(_merge_simple, front_idx=1, back_idx=0),
}


class AdjustedArray(object):
    """
    An array that can be iterated with a variable-length window, and which can
    provide different views on data from different perspectives.

    Parameters
    ----------
    data : np.ndarray
        The baseline data values.
    adjustments : dict[int -> list[Adjustment]]
        A dict mapping row indices to lists of adjustments to apply when we
        reach that row.
    missing_value : object
        A value to use to fill missing data in yielded windows.
        Should be a value coercible to `data.dtype`.

Review comment (suggestion):
Since you're copying anyway, another way to write this might be: `adjustment_lists[front_idx] + adjustment_lists[back_idx]`

Code after:
    -----
    This method is meant to be used with ``toolz.merge_with`` to merge
    adjustment mappings. In case of a collision ``adjustment_lists`` contains
    two lists, existing adjustments at index 0 and new adjustments at index 1.
    When there are no collisions, ``adjustment_lists`` contains a single list.

    Parameters
    ----------
    adjustment_lists : list[list[Adjustment]]
        List(s) of new and/or existing adjustments for a given index.
    front_idx : int
        Index of list in ``adjustment_lists`` that should be used as baseline
        in case of a collision.
    back_idx : int
        Index of list in ``adjustment_lists`` that should extend baseline list
        in case of a collision.

    Returns
    -------
    adjustments : list[Adjustment]
        List of merged adjustments for a given index.
    """
    if len(adjustment_lists) == 1:
        return list(adjustment_lists[0])
    else:
        return adjustment_lists[front_idx] + adjustment_lists[back_idx]


_merge_methods = {
    'append': partial(_merge_simple, front_idx=0, back_idx=1),
    'prepend': partial(_merge_simple, front_idx=1, back_idx=0),
}


class AdjustedArray(object):
    """
    An array that can be iterated with a variable-length window, and which can
    provide different views on data from different perspectives.

    Parameters
    ----------
    data : np.ndarray
        The baseline data values.
    adjustments : dict[int -> list[Adjustment]]
        A dict mapping row indices to lists of adjustments to apply when we
        reach that row.
    missing_value : object
        A value to use to fill missing data in yielded windows.
        Should be a value coercible to `data.dtype`.
    """
    __slots__ = (