diff --git a/src/pyobo/api/xrefs.py b/src/pyobo/api/xrefs.py index 515a6202..7cbcd00c 100644 --- a/src/pyobo/api/xrefs.py +++ b/src/pyobo/api/xrefs.py @@ -133,46 +133,41 @@ def get_sssom_df( rows = [] with logging_redirect_tqdm(): for source_id, target_prefix, target_id in tqdm(df.values, unit="mapping", unit_scale=True): - row = ( - bioregistry.curie_to_str(prefix, source_id), - bioregistry.curie_to_str(target_prefix, target_id), - predicate_id, - justification, - ) if names: - row = (*row, get_name(prefix, source_id) or "", get_name(target_prefix, target_id)) - rows.append(row) - - if not names: - return pd.DataFrame( - rows, - columns=[ - "subject_id", - "object_id", - "predicate_id", - "mapping_justification", - ], - ) - - df = pd.DataFrame( - rows, - columns=[ + rows.append( + ( + bioregistry.curie_to_str(prefix, source_id), + bioregistry.curie_to_str(target_prefix, target_id), + predicate_id, + justification, + ) + ) + else: + rows.append( + ( + bioregistry.curie_to_str(prefix, source_id), + get_name(prefix, source_id) or "", + bioregistry.curie_to_str(target_prefix, target_id), + get_name(target_prefix, target_id), + predicate_id, + justification, + ) + ) + + if names: + columns = [ "subject_id", + "subject_label", "object_id", + "object_label", "predicate_id", "mapping_justification", - "subject_label", - "object_label", - ], - ) - # reorder columns - return df[ - [ + ] + else: + columns = [ "subject_id", - "subject_label", "object_id", - "object_label", "predicate_id", "mapping_justification", ] - ] + return pd.DataFrame(rows, columns=columns)