mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-08 10:52:23 +08:00
MAINT: Use numpy_utils.as_column in more places.
This commit is contained in:
@@ -59,6 +59,7 @@ from .asset_db_schema import (
|
||||
)
|
||||
from zipline.utils.control_flow import invert
|
||||
from zipline.utils.memoize import lazyval
|
||||
from zipline.utils.numpy_utils import as_column
|
||||
from zipline.utils.sqlite_utils import group_into_chunks
|
||||
|
||||
log = Logger('assets.py')
|
||||
@@ -1096,7 +1097,7 @@ class AssetFinder(object):
|
||||
self._asset_lifetimes = self._compute_asset_lifetimes()
|
||||
lifetimes = self._asset_lifetimes
|
||||
|
||||
raw_dates = dates.asi8[:, None]
|
||||
raw_dates = as_column(dates.asi8)
|
||||
if include_start_date:
|
||||
mask = lifetimes.start <= raw_dates
|
||||
else:
|
||||
|
||||
@@ -18,7 +18,11 @@ from toolz.curried.operator import getitem
|
||||
|
||||
from zipline.lib.adjusted_array import ensure_adjusted_array, ensure_ndarray
|
||||
from zipline.errors import NoFurtherDataError
|
||||
from zipline.utils.numpy_utils import repeat_first_axis, repeat_last_axis
|
||||
from zipline.utils.numpy_utils import (
|
||||
as_column,
|
||||
repeat_first_axis,
|
||||
repeat_last_axis,
|
||||
)
|
||||
from zipline.utils.pandas_utils import explode
|
||||
|
||||
from .term import AssetExists, InputDates, LoadableTerm
|
||||
@@ -181,7 +185,7 @@ class SimplePipelineEngine(object):
|
||||
assets,
|
||||
initial_workspace={
|
||||
self._root_mask_term: root_mask_values,
|
||||
self._root_mask_dates_term: dates.values[:, None],
|
||||
self._root_mask_dates_term: as_column(dates.values)
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ from pandas import (
|
||||
)
|
||||
from zipline.lib.adjusted_array import AdjustedArray
|
||||
from zipline.lib.adjustment import make_adjustment_from_labels
|
||||
from zipline.utils.numpy_utils import as_column
|
||||
from zipline.utils.pandas_utils import sort_values
|
||||
from .base import PipelineLoader
|
||||
|
||||
@@ -169,7 +170,7 @@ class DataFrameLoader(PipelineLoader):
|
||||
# Pull out requested columns/rows from our baseline data.
|
||||
data=self.baseline[ix_(date_indexer, assets_indexer)],
|
||||
# Mask out requested columns/rows that didnt match.
|
||||
mask=(good_assets & good_dates[:, None]) & mask,
|
||||
mask=(good_assets & as_column(good_dates)) & mask,
|
||||
adjustments=self.format_adjustments(dates, assets),
|
||||
missing_value=column.missing_value,
|
||||
),
|
||||
|
||||
@@ -47,9 +47,11 @@ from zipline.pipeline.engine import SimplePipelineEngine
|
||||
from zipline.pipeline.factors import CustomFactor
|
||||
from zipline.pipeline.loaders.testing import make_seeded_random_loader
|
||||
from zipline.utils import security_list
|
||||
from zipline.utils.input_validation import expect_dimensions
|
||||
from zipline.utils.sentinel import sentinel
|
||||
from zipline.utils.calendars import get_calendar
|
||||
from zipline.utils.input_validation import expect_dimensions
|
||||
from zipline.utils.numpy_utils import as_column
|
||||
from zipline.utils.sentinel import sentinel
|
||||
|
||||
import numpy as np
|
||||
from numpy import float64
|
||||
|
||||
@@ -308,11 +310,11 @@ def make_trade_data_for_asset_info(dates,
|
||||
price_sid_deltas = np.arange(len(sids), dtype=float64) * price_step_by_sid
|
||||
price_date_deltas = (np.arange(len(dates), dtype=float64) *
|
||||
price_step_by_date)
|
||||
prices = (price_sid_deltas + price_date_deltas[:, None]) + price_start
|
||||
prices = (price_sid_deltas + as_column(price_date_deltas)) + price_start
|
||||
|
||||
volume_sid_deltas = np.arange(len(sids)) * volume_step_by_sid
|
||||
volume_date_deltas = np.arange(len(dates)) * volume_step_by_date
|
||||
volumes = (volume_sid_deltas + volume_date_deltas[:, None]) + volume_start
|
||||
volumes = volume_sid_deltas + as_column(volume_date_deltas) + volume_start
|
||||
|
||||
for j, sid in enumerate(sids):
|
||||
start_date, end_date = asset_info.loc[sid, ['start_date', 'end_date']]
|
||||
|
||||
Reference in New Issue
Block a user