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

Allow unordered df schema loading #970

Merged
merged 2 commits into from
Jun 21, 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
3 changes: 0 additions & 3 deletions .codespellrc

This file was deleted.

26 changes: 5 additions & 21 deletions hed/schema/schema_io/df2schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,35 +137,19 @@ def _read_schema(self, dataframe):
Parameters:
dataframe (pd.DataFrame): The dataframe for the main tags section
"""
# note: this assumes loading is in order row by row.
# If tags are NOT sorted this won't work.(same as mediawiki)
self._schema._initialize_attributes(HedSectionKey.Tags)
known_tag_levels = {"HedTag": -1}
parent_tags = []
known_parent_tags = {"HedTag": []}
level_adj = 0
for row_number, row in dataframe[constants.TAG_KEY].iterrows():
# skip blank rows, though there shouldn't be any
if not any(row):
continue
parent_tag = row[constants.subclass_of]
# Return -1 by default for top level rooted tag support(they might not be in the dict)
raw_level = known_tag_levels.get(parent_tag, -1) + 1
if raw_level == 0:
parent_tags = []
level_adj = 0
else:
level = raw_level + level_adj
if level < len(parent_tags):
parent_tags = parent_tags[:level]
elif level > len(parent_tags):
self._add_fatal_error(row_number, row,
"Invalid level reported from Level column",
HedExceptions.GENERIC_ERROR)
continue

tag_entry, parent_tags, level_adj = self._add_tag_meta(parent_tags, row_number, row, level_adj)
org_parent_tags = known_parent_tags.get(parent_tag, []).copy()

tag_entry, parent_tags, _ = self._add_tag_meta(org_parent_tags, row_number, row, level_adj)
if tag_entry:
known_tag_levels[tag_entry.short_tag_name] = raw_level
known_parent_tags[tag_entry.short_tag_name] = parent_tags.copy()

def _read_section(self, df, section_key):
self._schema._initialize_attributes(section_key)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ namespaces = false
hed = ["schema/schema_data/*.xml", "resources/*.png"]

[tool.codespell]
skip = '*.git,*.pdf,*.xml,*.mediawiki,*.svg,versioneer.py,venv*,*.tsv,*.yaml,*.yml,*.json,*.rdf,*.jsonld,spec_tests'
skip = '*.git,*.pdf,*.svg,versioneer.py,venv*,*.tsv,*.yaml,*.yml,*.json,*.rdf,*.jsonld,spec_tests,,*.xml,*.mediawiki,*.omn,*.toml'
ignore-words-list = 'te,parms,assertIn'