From e3d19bab25ddc5e6856b795411c0ee7eca566223 Mon Sep 17 00:00:00 2001 From: Scott Sanderson Date: Thu, 10 Dec 2015 14:19:32 -0500 Subject: [PATCH] MAINT: Fix failing blaze expr test. --- tests/pipeline/test_earnings.py | 6 ++++-- zipline/pipeline/loaders/blaze/earnings.py | 5 ++--- zipline/pipeline/loaders/earnings.py | 25 +++++++++++++++++++--- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/tests/pipeline/test_earnings.py b/tests/pipeline/test_earnings.py index 88232c36..32509005 100644 --- a/tests/pipeline/test_earnings.py +++ b/tests/pipeline/test_earnings.py @@ -388,7 +388,9 @@ class BlazeEarningsCalendarLoaderNotInteractiveTestCase( BlazeEarningsCalendarLoaderNotInteractiveTestCase, self, ).loader_args(dates) + + expr = bz.symbol('expr', bound_expr.dshape) return ( - bz.symbol('expr', bound_expr.dshape), - bound_expr._resources()[bound_expr], + expr, + {expr: bound_expr._resources()[bound_expr]}, ) diff --git a/zipline/pipeline/loaders/blaze/earnings.py b/zipline/pipeline/loaders/blaze/earnings.py index 45357364..6c90b16b 100644 --- a/zipline/pipeline/loaders/blaze/earnings.py +++ b/zipline/pipeline/loaders/blaze/earnings.py @@ -49,9 +49,8 @@ class BlazeEarningsCalendarLoader(PipelineLoader): ---------- expr : Expr The expression representing the data to load. - resources : any, optional - The resources to use when computing ``expr``. If expr is already - bound to resources this can be omitted. + resources : dict, optional + Mapping from the atomic terms of ``expr`` to actual data resources. odo_kwargs : dict, optional Extra keyword arguments to pass to odo when executing the expression. diff --git a/zipline/pipeline/loaders/earnings.py b/zipline/pipeline/loaders/earnings.py index 441c6a48..acde30ef 100644 --- a/zipline/pipeline/loaders/earnings.py +++ b/zipline/pipeline/loaders/earnings.py @@ -28,10 +28,23 @@ class EarningsCalendarLoader(PipelineLoader): all_dates : pd.DatetimeIndex Index of dates for which we can serve queries. announcement_dates : dict[int -> pd.Series or pd.DatetimeIndex] - Dict mapping sids to an index of dates on which earnings were - announced. + Dict mapping sids to objects representing dates on which earnings + occurred. + + If a dict value is a Series, it's interpreted as a mapping from the + date on which we learned an announcement was coming to the date on + which the announcement was made. + + If a dict value is a DatetimeIndex, it's interpreted as just containing + the dates that announcements were made, and we assume we knew about the + announcement on all prior dates. This mode is only supported if + ``infer_timestamp`` is explicitly passed as a truthy value. + + infer_timestamps : bool, optional + Whether to allow passing ``DatetimeIndex`` values in + ``announcement_dates``. """ - def __init__(self, all_dates, announcement_dates): + def __init__(self, all_dates, announcement_dates, infer_timestamps=False): self._all_dates = all_dates self._announcement_dates = announcement_dates = ( @@ -40,6 +53,12 @@ class EarningsCalendarLoader(PipelineLoader): dates = self._all_dates.values for k, v in iteritems(announcement_dates): if isinstance(v, pd.DatetimeIndex): + if not infer_timestamps: + raise ValueError( + "Got DatetimeIndex of announcement dates for sid %d.\n" + "Pass `infer_timestamps=True` to use the first date in" + " `all_dates` as implicit timestamp." + ) # If we are passed a DatetimeIndex, we always have # knowledge of the announcements. announcement_dates[k] = pd.Series(