def create_expected_df_for_factor_compute(start_date, sids, tuples, end_date):
 df = pd.DataFrame(tuples, columns=[SID_FIELD_NAME, 'estimate', 'knowledge_date'])
 df = df.pivot_table(columns=SID_FIELD_NAME, values='estimate', index='knowledge_date')
 df = df.reindex(pd.date_range(start_date, end_date))
 df.index = df.index.rename('knowledge_date')
 df['at_date'] = end_date.tz_localize('utc')
 df = df.set_index(['at_date', df.index.tz_localize('utc')]).ffill()
 new_sids = (set(sids) - set(df.columns))
 df = df.reindex(columns=df.columns.union(new_sids))
 return df

def create_expected_df_for_factor_compute ( start_date , sids , tuples , end_date ) : df = pd . DataFrame ( tuples , columns = [ SID_FIELD_NAME , 'estimate' , 'knowledge_date' ] ) df = df . pivot_table ( columns = SID_FIELD_NAME , values = 'estimate' , index = 'knowledge_date' ) df = df . reindex ( pd . date_range ( start_date , end_date ) ) df . index = df . index . rename ( 'knowledge_date' ) df [ 'at_date' ] = end_date . tz_localize ( 'utc' ) df = df . set_index ( [ 'at_date' , df . index . tz_localize ( 'utc' ) ] ) . ffill ( ) new_sids = ( set ( sids ) - set ( df . columns ) ) df = df . reindex ( columns = df . columns . union ( new_sids ) ) return df
given a list of tuples of new data we get for each sid on each critical date .