From 586a41ff7c9f16d06b52720e9f62d155bd36a473 Mon Sep 17 00:00:00 2001 From: Joe Jevnik Date: Mon, 8 Aug 2016 16:39:24 -0400 Subject: [PATCH] DOC: explain the group by and inner select more --- zipline/assets/assets.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/zipline/assets/assets.py b/zipline/assets/assets.py index 6bfeb9f4..f8620ddc 100644 --- a/zipline/assets/assets.py +++ b/zipline/assets/assets.py @@ -441,6 +441,29 @@ class AssetFinder(object): return sa.select([asset_tbl]).where(asset_tbl.c.symbol == symbol) def _select_most_recent_symbols_chunk(self, sid_group): + """Retrieve the most recent symbol for a set of sids. + + Parameters + ---------- + sid_group : iterable[int] + The sids to lookup. The length of this sequence must be less than + or equal to SQLITE_MAX_VARIABLE_NUMBER because the sids will be + passed in as sql bind params. + + Returns + ------- + sel : Selectable + The sqlalchemy selectable that will query for the most recent + symbol for each sid. + + Notes + ----- + This is implemented as an inner select of the columns of interest + ordered by the end date of the (sid, symbol) mapping. We then group + that inner select on the sid with no aggregations to select the last + row per group which gives us the most recently active symbol for all + of the sids. + """ symbol_cols = self.equity_symbol_mappings.c inner = sa.select( (symbol_cols.sid,) +