diff --git a/hed/schema/schema_io/ontology_util.py b/hed/schema/schema_io/ontology_util.py index da68197c6..5e3803355 100644 --- a/hed/schema/schema_io/ontology_util.py +++ b/hed/schema/schema_io/ontology_util.py @@ -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 @@ -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 diff --git a/hed/schema/schema_io/schema2df.py b/hed/schema/schema_io/schema2df.py index 7917eb2f4..9c2b6c798 100644 --- a/hed/schema/schema_io/schema2df.py +++ b/hed/schema/schema_io/schema2df.py @@ -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 @@ -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 diff --git a/requirements.txt b/requirements.txt index 9af8a52d8..ff3ca85e2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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