Skip to content

Commit 1d8a15e

Browse files
committed
Addressed review in hed-standard#1247
1 parent 4806eda commit 1d8a15e

19 files changed

Lines changed: 48 additions & 133 deletions

hed/errors/error_messages.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def val_error_def_value_missing(tag):
272272

273273
@hed_tag_error(ValidationErrors.HED_DEF_VALUE_EXTRA, actual_code=ValidationErrors.DEF_INVALID)
274274
def val_error_def_value_extra(tag):
275-
return f"A def tag does not take a placeholder value, but was given one. Definition: '{tag}"
275+
return f"A def tag does not take a placeholder value, but was given one. Definition: '{tag}'"
276276

277277

278278
@hed_tag_error(ValidationErrors.HED_DEF_EXPAND_UNMATCHED, actual_code=ValidationErrors.DEF_EXPAND_INVALID)
@@ -287,7 +287,7 @@ def val_error_def_expand_value_missing(tag):
287287

288288
@hed_tag_error(ValidationErrors.HED_DEF_EXPAND_VALUE_EXTRA, actual_code=ValidationErrors.DEF_EXPAND_INVALID)
289289
def val_error_def_expand_value_extra(tag):
290-
return f"A Def-expand tag does not take a placeholder value, but was given one. Definition: '{tag}"
290+
return f"A Def-expand tag does not take a placeholder value, but was given one. Definition: '{tag}'"
291291

292292

293293
@hed_tag_error(ValidationErrors.HED_TOP_LEVEL_TAG, actual_code=ValidationErrors.TAG_GROUP_ERROR)

hed/errors/exceptions.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,8 @@ class HedExceptions:
1818
INVALID_FILE_FORMAT = "INVALID_FILE_FORMAT"
1919

2020
# These are actual schema issues, not that the file cannot be found or parsed
21-
SCHEMA_HEADER_MISSING = "SCHEMA_HEADER_INVALID"
2221
SCHEMA_HEADER_INVALID = "SCHEMA_HEADER_INVALID"
23-
SCHEMA_UNKNOWN_HEADER_ATTRIBUTE = "SCHEMA_HEADER_INVALID"
24-
2522
SCHEMA_LIBRARY_INVALID = "SCHEMA_LIBRARY_INVALID"
26-
BAD_HED_LIBRARY_NAME = "SCHEMA_LIBRARY_INVALID"
27-
BAD_WITH_STANDARD = "SCHEMA_LIBRARY_INVALID"
28-
BAD_WITH_STANDARD_MULTIPLE_VALUES = "SCHEMA_LOAD_FAILED"
29-
ROOTED_TAG_INVALID = "SCHEMA_LIBRARY_INVALID"
30-
ROOTED_TAG_HAS_PARENT = "SCHEMA_LIBRARY_INVALID"
31-
ROOTED_TAG_DOES_NOT_EXIST = "SCHEMA_LIBRARY_INVALID"
32-
IN_LIBRARY_IN_UNMERGED = "SCHEMA_LIBRARY_INVALID"
33-
INVALID_LIBRARY_PREFIX = "SCHEMA_LIBRARY_INVALID"
34-
3523
SCHEMA_VERSION_INVALID = "SCHEMA_VERSION_INVALID"
3624
SCHEMA_SECTION_MISSING = "SCHEMA_SECTION_MISSING"
3725
SCHEMA_INVALID = "SCHEMA_INVALID"
@@ -44,7 +32,6 @@ class HedExceptions:
4432
WIKI_LINE_INVALID = "WIKI_LINE_INVALID"
4533
HED_SCHEMA_NODE_NAME_INVALID = "HED_SCHEMA_NODE_NAME_INVALID"
4634

47-
SCHEMA_DUPLICATE_PREFIX = "SCHEMA_LOAD_FAILED"
4835
SCHEMA_DUPLICATE_LIBRARY = "SCHEMA_LIBRARY_INVALID"
4936
BAD_COLUMN_NAMES = "BAD_COLUMN_NAMES"
5037

hed/schema/hed_schema_group.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def __init__(self, schema_list, name=""):
4343
schema_prefixes = [hed_schema._namespace for hed_schema in schema_list]
4444
if len(set(schema_prefixes)) != len(schema_prefixes):
4545
raise HedFileError(
46-
HedExceptions.SCHEMA_DUPLICATE_PREFIX,
47-
"Multiple schema share the same tag name_prefix. This is not allowed.",
46+
HedExceptions.SCHEMA_LOAD_FAILED,
47+
"Multiple schema share the same tag name_prefix so schema cannot be loaded.",
4848
filename=self.name,
4949
)
5050
self._schemas = {hed_schema._namespace: hed_schema for hed_schema in schema_list}

hed/schema/schema_header_util.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ def validate_library_name(library_name):
1717
"""
1818
for i, character in enumerate(library_name):
1919
if not character.isalpha():
20-
return f"Non alpha character '{character}' at position {i} in '{library_name}'"
20+
return f"Non alpha character '{character}' at position {i} in library name '{library_name}'"
2121
if character.isupper():
22-
return f"Non lowercase character '{character}' at position {i} in '{library_name}'"
22+
return f"Non lowercase character '{character}' at position {i} in library name '{library_name}'"
2323

2424

2525
def validate_version_string(version_string):
@@ -41,7 +41,7 @@ def validate_version_string(version_string):
4141

4242
header_attribute_validators = {
4343
constants.VERSION_ATTRIBUTE: (validate_version_string, HedExceptions.SCHEMA_VERSION_INVALID),
44-
constants.LIBRARY_ATTRIBUTE: (validate_library_name, HedExceptions.BAD_HED_LIBRARY_NAME),
44+
constants.LIBRARY_ATTRIBUTE: (validate_library_name, HedExceptions.SCHEMA_LIBRARY_INVALID),
4545
}
4646

4747

@@ -61,7 +61,7 @@ def validate_present_attributes(attrib_dict, name):
6161
"""
6262
if constants.WITH_STANDARD_ATTRIBUTE in attrib_dict and constants.LIBRARY_ATTRIBUTE not in attrib_dict:
6363
raise HedFileError(
64-
HedExceptions.BAD_WITH_STANDARD,
64+
HedExceptions.SCHEMA_LIBRARY_INVALID,
6565
"withStandard header attribute found, but no library attribute is present",
6666
name,
6767
)
@@ -93,7 +93,7 @@ def validate_attributes(attrib_dict, name):
9393
raise HedFileError(error_code, had_error, name)
9494
if attribute_name not in valid_header_attributes:
9595
raise HedFileError(
96-
HedExceptions.SCHEMA_UNKNOWN_HEADER_ATTRIBUTE,
96+
HedExceptions.SCHEMA_HEADER_INVALID,
9797
f"Unknown attribute {attribute_name} found in header line",
9898
filename=name,
9999
)

hed/schema/schema_io/base2schema.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ def __init__(self, filename, schema_as_string=None, schema=None, file_format=Non
6363
self.appending_to_schema = True
6464
if not self._schema.with_standard:
6565
raise HedFileError(
66-
HedExceptions.SCHEMA_DUPLICATE_PREFIX,
66+
HedExceptions.SCHEMA_LOAD_FAILED,
6767
"Loading multiple normal schemas as a merged one with the same namespace. "
6868
"Ensure schemas have the withStandard header attribute set",
6969
self.name,
7070
)
7171
elif with_standard != self._schema.with_standard:
7272
raise HedFileError(
73-
HedExceptions.BAD_WITH_STANDARD_MULTIPLE_VALUES,
73+
HedExceptions.SCHEMA_LOAD_FAILED,
7474
f"Merging schemas requires same withStandard value ({with_standard} != {self._schema.with_standard}).",
7575
self.name,
7676
)
@@ -125,7 +125,7 @@ def _load(self):
125125
base_version = load_schema_version(self._schema.with_standard, check_prerelease=self.check_prerelease)
126126
except HedFileError as e:
127127
raise HedFileError(
128-
HedExceptions.BAD_WITH_STANDARD,
128+
HedExceptions.SCHEMA_LIBRARY_INVALID,
129129
message=f"Cannot load withStandard schema '{self._schema.with_standard}'",
130130
filename=e.filename,
131131
) from e
@@ -194,36 +194,36 @@ def find_rooted_entry(tag_entry, schema, loading_merged):
194194
if rooted_tag is not None:
195195
if not schema.with_standard:
196196
raise HedFileError(
197-
HedExceptions.ROOTED_TAG_INVALID,
197+
HedExceptions.SCHEMA_ATTRIBUTE_INVALID,
198198
f"Rooted tag attribute found on '{tag_entry.short_tag_name}' in a standard schema.",
199199
schema.name,
200200
)
201201

202202
if not isinstance(rooted_tag, str):
203203
raise HedFileError(
204-
HedExceptions.ROOTED_TAG_INVALID,
204+
HedExceptions.SCHEMA_LIBRARY_INVALID,
205205
f"Rooted tag '{tag_entry.short_tag_name}' is not a string.\"",
206206
schema.name,
207207
)
208208

209209
if tag_entry.parent_name and not loading_merged:
210210
raise HedFileError(
211-
HedExceptions.ROOTED_TAG_INVALID,
211+
HedExceptions.SCHEMA_LIBRARY_INVALID,
212212
f"Found rooted tag '{tag_entry.short_tag_name}' as a non root node.",
213213
schema.name,
214214
)
215215

216216
if not tag_entry.parent_name and loading_merged:
217217
raise HedFileError(
218-
HedExceptions.ROOTED_TAG_INVALID,
218+
HedExceptions.SCHEMA_LIBRARY_INVALID,
219219
f"Found rooted tag '{tag_entry.short_tag_name}' as a root node in a merged schema.",
220220
schema.name,
221221
)
222222

223223
rooted_entry = schema.tags.get(rooted_tag)
224224
if not rooted_entry or rooted_entry.has_attribute(constants.HedKey.InLibrary):
225225
raise HedFileError(
226-
HedExceptions.ROOTED_TAG_DOES_NOT_EXIST,
226+
HedExceptions.LIBRARY_SCHEMA_INVALID,
227227
f"Rooted tag '{tag_entry.short_tag_name}' not found in paired standard schema",
228228
schema.name,
229229
)

hed/schema/schema_io/wiki2schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def _get_header_attributes(self, file_data):
7777
hed_attributes = self._get_header_attributes_internal(line[len(wiki_constants.HEADER_LINE_STRING) :])
7878
return hed_attributes
7979
msg = f"First line of file should be HED, instead found: {line}"
80-
raise HedFileError(HedExceptions.SCHEMA_HEADER_MISSING, msg, filename=self.name)
80+
raise HedFileError(HedExceptions.SCHEMA_HEADER_INVALID, msg, filename=self.name)
8181

8282
def _parse_data(self):
8383
wiki_lines_by_section = self._split_lines_into_sections(self.input_data)

hed/tools/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from .bids.bids_util import parse_bids_filename
2121

2222
from .util.data_util import get_new_dataframe, get_value_dict, replace_values, reorder_columns
23-
from .util.io_util import check_filename, clean_filename, extract_suffix_path, get_file_list, make_path
23+
from .util.io_util import check_filename, clean_filename, extract_suffix_path, get_file_list
2424
from .util.io_util import get_path_components
2525

2626
from .analysis.annotation_util import (

hed/tools/analysis/annotation_util.py

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -367,37 +367,6 @@ def _flatten_val_col(col_key, col_dict) -> tuple[list[str], list[str], list[str]
367367
return [col_key], ["n/a"], [description], [tags]
368368

369369

370-
# def _get_row_tags(row, description_tag=True):
371-
# """ Return the HED string associated with row, possibly without the description.
372-
#
373-
# Parameters:
374-
# row (DataSeries): Pandas data frame containing a row of a tagging spreadsheet.
375-
# description_tag (bool): If True, include any Description tags in the returned string.
376-
#
377-
# Returns:
378-
# str: A HED string extracted from the row.
379-
# str: A string representing the description (without the Description tag).
380-
#
381-
# Notes:
382-
# If description_tag is True the entire tag string is included with description.
383-
# If there was a description extracted, it is appended to any existing description.
384-
#
385-
# """
386-
# remainder, extracted = extract_tags(row['HED'], 'Description/')
387-
# if description_tag:
388-
# tags = row["HED"]
389-
# else:
390-
# tags = remainder
391-
#
392-
# if row["description"] != 'n/a':
393-
# description = row["description"]
394-
# else:
395-
# description = ""
396-
# if extracted:
397-
# description = " ".join([description, extracted])
398-
# return tags, description
399-
400-
401370
def _get_value_entry(hed_entry, description_entry, description_tag=True):
402371
"""Return a HED dictionary representing a value entry in a HED tagging spreadsheet.
403372
@@ -473,24 +442,3 @@ def _update_cat_dict(cat_dict, value_entry, hed_entry, description_entry, descri
473442
hed_part = cat_dict.get("HED", {})
474443
hed_part[value_entry] = value_dict["HED"]
475444
cat_dict["HED"] = hed_part
476-
477-
478-
# def _update_remainder(remainder, update_piece):
479-
# """ Update remainder with update piece.
480-
#
481-
# Parameters:
482-
# remainder (str): A tag string without trailing comma.
483-
# update_piece (str): A tag string to be appended.
484-
#
485-
# Returns:
486-
# str: A concatenation of remainder and update_piece, paying attention to separating commas.
487-
#
488-
# """
489-
# if not update_piece:
490-
# return remainder
491-
# elif not remainder:
492-
# return update_piece
493-
# elif remainder.endswith(')') or update_piece.startswith('('):
494-
# return remainder + update_piece
495-
# else:
496-
# return remainder + ", " + update_piece

hed/tools/analysis/hed_tag_counts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def merge_tag_dicts(self, other_dict):
143143
continue
144144
for value, val_count in count.value_dict.items():
145145
if value in self.tag_dict[tag].value_dict:
146-
self.tag_dict[tag].value_dict[value] = self.tag_dict[tag].value_dict + val_count
146+
self.tag_dict[tag].value_dict[value] = self.tag_dict[tag].value_dict[value] + val_count
147147
else:
148148
self.tag_dict[tag].value_dict[value] = val_count
149149

hed/tools/analysis/hed_type_factors.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Manager for factor information for a columnar file."""
22

33
import pandas as pd
4-
from hed.errors.exceptions import HedFileError
4+
from hed.errors.exceptions import HedExceptions, HedFileError
55

66

77
class HedTypeFactors:
@@ -58,15 +58,17 @@ def get_factors(self, factor_encoding="one-hot"):
5858
sum_factors = factors.sum(axis=1)
5959
if factor_encoding == "categorical" and sum_factors.max() > 1:
6060
raise HedFileError(
61-
"MultipleFactorSameEvent",
61+
HedExceptions.BAD_PARAMETERS,
6262
f"{self.type_value} has multiple occurrences at index {sum_factors.idxmax()}",
6363
"",
6464
)
6565
elif factor_encoding == "categorical":
6666
return self._one_hot_to_categorical(factors, levels)
6767
else:
68-
raise ValueError(
69-
"BadFactorEncoding", f"{factor_encoding} is not in the allowed encodings: {str(self.ALLOWED_ENCODINGS)}"
68+
raise HedFileError(
69+
HedExceptions.BAD_PARAMETERS,
70+
f"{factor_encoding} is not in the allowed encodings: {str(self.ALLOWED_ENCODINGS)}",
71+
"",
7072
)
7173

7274
def _one_hot_to_categorical(self, factors, levels):
@@ -77,7 +79,7 @@ def _one_hot_to_categorical(self, factors, levels):
7779
levels (list): List of categorical columns to convert.
7880
7981
Return:
80-
pd.ataFrame: Contains one-hot representation of requested levels.
82+
pd.DataFrame: Contains one-hot representation of requested levels.
8183
8284
"""
8385
df = pd.DataFrame("n/a", index=range(len(factors.index)), columns=[self.type_value])

0 commit comments

Comments
 (0)