Skip to content
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
9 changes: 8 additions & 1 deletion hed/schema/schema_io/ontology_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ def _get_hedid_range(schema_name, df_key):
return set(range(final_start, final_end))


# todo: Replace this once we no longer support < python 3.9
def remove_prefix(text, prefix):
if text and text.startswith(prefix):
return text[len(prefix):]
return text


def get_all_ids(df):
"""Returns a set of all unique hedIds in the dataframe

Expand All @@ -82,7 +89,7 @@ def get_all_ids(df):
numbers(Set or None): None if this has no hed column, otherwise all unique numbers as a set.
"""
if constants.hed_id in df.columns:
modified_df = df[constants.hed_id].str.removeprefix("HED_")
modified_df = df[constants.hed_id].apply(lambda x: remove_prefix(x, "HED_"))
modified_df = pd.to_numeric(modified_df, errors="coerce").dropna().astype(int)
return set(modified_df.unique())
return None
Expand Down
4 changes: 2 additions & 2 deletions hed/schema/schema_io/schema2df.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Allows output of HedSchema objects as .mediawiki format"""

from hed.schema.hed_schema_constants import HedSectionKey, HedKey
from hed.schema.schema_io.ontology_util import get_library_name_and_id
from hed.schema.schema_io.ontology_util import get_library_name_and_id, remove_prefix
from hed.schema.schema_io.schema2base import Schema2Base
import pandas as pd
import hed.schema.hed_schema_df_constants as constants
Expand Down Expand Up @@ -40,7 +40,7 @@ def _get_object_name_and_id(self, object_name, include_prefix=False):
hed_id(str): The full formatted hed_id
"""
prefix, obj_id = get_library_name_and_id(self._schema)
name = f"{prefix}{object_name.removeprefix('Hed')}"
name = f"{prefix}{remove_prefix(object_name, 'Hed')}"
full_hed_id = self._get_object_id(object_name, obj_id, include_prefix)
return name, full_hed_id

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defusedxml>=0.7.1
inflect>=6.0.5
jsonschema>=4.17.3
matplotlib>=3.8.3
matplotlib>=3
numpy>=1.21.6
openpyxl>=3.1.0
pandas>=1.3.5
Expand Down