def build_ownership_map(table, key_from_row, value_from_row):
 rows = sa.select(table.c).execute().fetchall()
 mappings = {}
 for row in rows:
  mappings.setdefault(key_from_row(row), []).append(OwnershipPeriod(pd.Timestamp(row.start_date, unit='ns', tz='utc'), pd.Timestamp(row.end_date, unit='ns', tz='utc'), row.sid, value_from_row(row)))
 return merge_ownership_periods(mappings)

def build_ownership_map ( table , key_from_row , value_from_row ) : rows = sa . select ( table . c ) . execute ( ) . fetchall ( ) mappings = { } for row in rows : mappings . setdefault ( key_from_row ( row ) , [ ] ) . append ( OwnershipPeriod ( pd . Timestamp ( row . start_date , unit = 'ns' , tz = 'utc' ) , pd . Timestamp ( row . end_date , unit = 'ns' , tz = 'utc' ) , row . sid , value_from_row ( row ) ) ) return merge_ownership_periods ( mappings )
builds a dict mapping to lists of ownershipperiods .