Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make assigning ID's optional in script #923

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions hed/schema/schema_io/ontology_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,16 @@ def get_all_ids(df):
return None


def update_dataframes_from_schema(dataframes, schema, schema_name="", get_as_ids=False):
def update_dataframes_from_schema(dataframes, schema, schema_name="", get_as_ids=False,
assign_missing_ids=False):
""" Write out schema as a dataframe, then merge in extra columns from dataframes.

Parameters:
dataframes(dict of str:pd.DataFrames): A full set of schema spreadsheet formatted dataframes
schema(HedSchema): The schema to write into the dataframes:
schema_name(str): The name to use to find the schema id range.
get_as_ids(bool): If True, replace all known references with HedIds
assign_missing_ids(bool): If True, replacing any blank(new) HedIds with valid ones

Returns:
dataframes(dict of str:pd.DataFrames): The updated dataframes
Expand All @@ -132,14 +134,15 @@ def update_dataframes_from_schema(dataframes, schema, schema_name="", get_as_ids
from hed.schema.schema_io.schema2df import Schema2DF # Late import as this is recursive
output_dfs = Schema2DF(get_as_ids=get_as_ids).process_schema(schema, save_merged=False)

# 3: Add any hed ID's as needed to these generated dfs
for df_key, df in output_dfs.items():
if df_key == constants.STRUCT_KEY:
continue
unused_tag_ids = _get_hedid_range(schema_name, df_key)
if assign_missing_ids:
# 3: Add any hed ID's as needed to these generated dfs
for df_key, df in output_dfs.items():
if df_key == constants.STRUCT_KEY:
continue
unused_tag_ids = _get_hedid_range(schema_name, df_key)

# If no errors, assign new hed ID's
assign_hed_ids_section(df, unused_tag_ids)
# If no errors, assign new hed ID's
assign_hed_ids_section(df, unused_tag_ids)

# 4: Merge the dataframes
for df_key in output_dfs.keys():
Expand Down
2 changes: 1 addition & 1 deletion tests/schema/test_ontology_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def test_update_dataframes_from_schema(self):
try:
updated_dataframes = update_dataframes_from_schema(schema_dataframes_new, schema)
except HedFileError as e:
self.assertEqual(len(e.issues), 86)
self.assertEqual(len(e.issues), 111)
breakHere = 3


Expand Down