Skip to content

Commit a23ece8

Browse files
committed
Replaced remove_prefix with built-in
1 parent 61027bb commit a23ece8

4 files changed

Lines changed: 5 additions & 15 deletions

File tree

hed/schema/schema_attribute_validator_hed_id.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from hed.schema.hed_cache import get_library_data
2-
from hed.schema.schema_io.df_util import remove_prefix
32
from semantic_version import Version
43
from hed.schema.hed_schema_io import load_schema_version
54
from hed.schema.hed_cache import get_hed_versions
@@ -87,13 +86,13 @@ def verify_tag_id(self, hed_schema, tag_entry, attribute_name):
8786

8887
if old_id:
8988
try:
90-
old_id = int(remove_prefix(old_id, "HED_"))
89+
old_id = int(old_id.removeprefix("HED_"))
9190
except ValueError:
9291
# Just silently ignore invalid old_id values(this shouldn't happen)
9392
pass
9493
if new_id:
9594
try:
96-
new_id = int(remove_prefix(new_id, "HED_"))
95+
new_id = int(new_id.removeprefix("HED_"))
9796
except ValueError:
9897
return ErrorHandler.format_error(SchemaAttributeErrors.SCHEMA_HED_ID_INVALID, tag_entry.name, new_id)
9998
# Nothing to verify

hed/schema/schema_io/df_util.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,6 @@ def get_library_name_and_id(schema):
233233
return name.capitalize(), starting_id
234234

235235

236-
# todo: Replace this once we no longer support < python 3.10
237-
def remove_prefix(text, prefix):
238-
if text and text.startswith(prefix):
239-
return text[len(prefix) :]
240-
return text
241-
242-
243236
def calculate_attribute_type(attribute_entry):
244237
"""Returns the type of this attribute(annotation, object, data)
245238

hed/schema/schema_io/hed_id_util.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from hed.schema.schema_io import schema_util
1010
from hed.errors.exceptions import HedFileError
1111
from hed.schema.hed_schema_constants import HedKey
12-
from hed.schema.schema_io.df_util import remove_prefix
1312
from hed.schema.hed_cache import get_library_data
1413
from hed.schema.schema_io import df_constants as constants
1514

@@ -67,7 +66,7 @@ def get_all_ids(df):
6766
Union[Set, None]: None if this has no HED column, otherwise all unique numbers as a set.
6867
"""
6968
if constants.hed_id in df.columns:
70-
modified_df = df[constants.hed_id].apply(lambda x: remove_prefix(x, "HED_"))
69+
modified_df = df[constants.hed_id].apply(lambda x: x.removeprefix("HED_") if x else x)
7170
modified_df = pd.to_numeric(modified_df, errors="coerce").dropna().astype(int)
7271
return set(modified_df.unique())
7372
return None
@@ -171,7 +170,7 @@ def _verify_hedid_matches(section, df, unused_tag_ids):
171170
row_number, row, f"'{label}' has an improperly formatted hedID in dataframe."
172171
)
173172
continue
174-
id_value = remove_prefix(df_id, "HED_")
173+
id_value = df_id.removeprefix("HED_")
175174
try:
176175
id_int = int(id_value)
177176
if id_int not in unused_tag_ids:

hed/schema/schema_io/schema2df.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from hed.schema.schema_io.df_util import (
55
create_empty_dataframes,
66
get_library_name_and_id,
7-
remove_prefix,
87
calculate_attribute_type,
98
)
109
from hed.schema.schema_io.schema2base import Schema2Base
@@ -49,7 +48,7 @@ def _get_object_name_and_id(self, object_name, include_prefix=False):
4948
- The full formatted hed_id.
5049
"""
5150
prefix, obj_id = get_library_name_and_id(self._schema)
52-
name = f"{prefix}{remove_prefix(object_name, 'Hed')}"
51+
name = f"{prefix}{object_name.removeprefix('Hed')}"
5352
full_hed_id = self._get_object_id(object_name, obj_id, include_prefix)
5453
return name, full_hed_id
5554

0 commit comments

Comments
 (0)