def update_joins(joins, new_downstreams, new_upstreams):
    """
    Update new upstream and downstream segment IDs into joins table.

    Parameters
    ----------
    joins : DataFrame
        contains records with upstream_id and downstream_id representing joins between segments
    new_dowstreams : Series
        Series, indexed on original line ID, with the new downstream ID for each original line ID
    new_upstreams : Series
        Series, indexed on original line ID, with the new upstream ID for each original line ID
    
    Returns
    -------
    DataFrame
    """
    joins = joins.join(new_downstreams, on='downstream_id').join(new_upstreams,
        on='upstream_id')
    idx = joins.new_downstream_id.notnull()
    joins.loc[idx, 'downstream_id'] = joins[idx].new_downstream_id.astype(
        'uint32')
    idx = joins.new_upstream_id.notnull()
    joins.loc[idx, 'upstream_id'] = joins[idx].new_upstream_id.astype('uint32')
    return joins.drop(columns=['new_downstream_id', 'new_upstream_id'])
