def last_in_date_group(df, dates, assets, reindex=True, have_sids=True, extra_groupers=[]):
 idx = [dates[dates.searchsorted(df[TS_FIELD_NAME].values.astype('datetime64[D]'))]]
 if have_sids:
  idx += [SID_FIELD_NAME]
 idx += extra_groupers
 last_in_group = df.drop(TS_FIELD_NAME, axis=1).groupby(idx, sort=False).last()
 for _ in range((len(idx) - 1)):
  last_in_group = last_in_group.unstack((-1))
 if reindex:
  if have_sids:
   cols = last_in_group.columns
   last_in_group = last_in_group.reindex(index=dates, columns=pd.MultiIndex.from_product((tuple(cols.levels[0:(len(extra_groupers) + 1)]) + (assets,)), names=cols.names))
  else:
   last_in_group = last_in_group.reindex(dates)
 return last_in_group

def last_in_date_group ( df , dates , assets , reindex = True , have_sids = True , extra_groupers = [ ] ) : idx = [ dates [ dates . searchsorted ( df [ TS_FIELD_NAME ] . values . astype ( 'datetime64[D]' ) ) ] ] if have_sids : idx += [ SID_FIELD_NAME ] idx += extra_groupers last_in_group = df . drop ( TS_FIELD_NAME , axis = 1 ) . groupby ( idx , sort = False ) . last ( ) for _ in range ( ( len ( idx ) - 1 ) ) : last_in_group = last_in_group . unstack ( ( - 1 ) ) if reindex : if have_sids : cols = last_in_group . columns last_in_group = last_in_group . reindex ( index = dates , columns = pd . MultiIndex . from_product ( ( tuple ( cols . levels [ 0 : ( len ( extra_groupers ) + 1 ) ] ) + ( assets , ) ) , names = cols . names ) ) else : last_in_group = last_in_group . reindex ( dates ) return last_in_group
determine the last piece of information known on each date in the date index for each group .