Repository: quantopian/zipline
File: zipline/pipeline/loaders/synthetic.py (Python)

Code before:
    """
    Return an 2D array containing cls.expected_value(asset_id, date,
    colname) for each date/asset pair in the inputs.

    Values before/after an assets lifetime, as well as the locs defined,
    in `holes` are filled with 0 for volume and NaN for price columns.
    """
    if colname == 'volume':
        dtype = uint32
        missing = 0
    else:
        dtype = float64
        missing = float('nan')

    assets = asset_info.index

    data = full((len(dates), len(assets)), missing, dtype=dtype)
    for j, asset in enumerate(assets):
        start = asset_start(asset_info, asset)
        end = asset_end(asset_info, asset)
        for i, date in enumerate(dates):
            # No value expected for dates outside the asset's start/end
            # date.
            if not (start <= date <= end):
                continue
            if (
                holes is not None and
                asset in holes and
                date in holes[asset]
            ):
                continue
            data[i, j] = expected_bar_value(asset, date, colname)
    return data


class NullAdjustmentReader(SQLiteAdjustmentReader):
    """
    A SQLiteAdjustmentReader that stores no adjustments and uses in-memory
    SQLite.
    """

    def __init__(self):
        conn = sqlite3_connect(':memory:')
        writer = SQLiteAdjustmentWriter(conn, None, None)
        empty = DataFrame({
            'sid': array([], dtype=uint32),
            'effective_date': array([], dtype=uint32),
            'ratio': array([], dtype=float),
        })
        empty_dividends = DataFrame({
            'sid': array([], dtype=uint32),

Review comment (suggestion):
I tend to try to avoid in-line complex conditionals in if-statements if I can.

This might be clearer if we added an in-line `is_hole` function at the start of this function like:

```python
def is_hole(date, asset):
    return holes is not None and date in holes.get(asset, ())
```
or maybe better yet:

```python
if holes is not None:
    def is_hole(date, asset):
        return date in holes.get(asset, ())
else:
    def is_hole(date, asset):
        return False
```

Code after:
                                  date,
                                  colname,
                                  holes,
                                  missing_value):
    # Explicit holes are filled with the missing value.
    if asset_id in holes and date in holes[asset_id]:
        return missing_value

    return expected_bar_value(asset_id, date, colname)


def expected_bar_values_2d(dates, asset_info, colname, holes=None):
    """
    Return an 2D array containing cls.expected_value(asset_id, date,
    colname) for each date/asset pair in the inputs.

    Values before/after an assets lifetime, as well as the locs defined,
    in `holes` are filled with 0 for volume and NaN for price columns.
    """
    if colname == 'volume':
        dtype = uint32
        missing = 0
    else:
        dtype = float64
        missing = float('nan')

    assets = asset_info.index

    data = full((len(dates), len(assets)), missing, dtype=dtype)
    for j, asset in enumerate(assets):
        start = asset_start(asset_info, asset)
        end = asset_end(asset_info, asset)
        for i, date in enumerate(dates):
            # No value expected for dates outside the asset's start/end
            # date.
            if not (start <= date <= end):
                continue

            if holes is not None:
                expected = expected_bar_value_with_holes(
                    asset,
                    date,
                    colname,
                    holes,
                    missing,
                )
            else:
                expected = expected_bar_value(asset, date, colname)

            data[i, j] = expected
    return data