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
53 changes: 35 additions & 18 deletions hed/errors/error_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ def val_error_invalid_tag_character(tag, problem_tag):
return f"Invalid character '{problem_tag}' in tag '{tag}'"


@hed_tag_error(ValidationErrors.INVALID_VALUE_CLASS_CHARACTER, has_sub_tag=True,
@hed_tag_error(ValidationErrors.INVALID_VALUE_CLASS_CHARACTER, has_sub_tag=False,
actual_code=ValidationErrors.CHARACTER_INVALID)
def val_error_INVALID_VALUE_CLASS_CHARACTER(tag, problem_tag, value_class):
def val_error_val_error_invalid_value_class_character(tag, problem_tag, value_class):
return f"Invalid character '{problem_tag}' in tag '{tag}' for value class '{value_class}'"


@hed_tag_error(ValidationErrors.INVALID_VALUE_CLASS_VALUE, has_sub_tag=True,
actual_code=ValidationErrors.VALUE_INVALID)
def val_error_INVALID_VALUE_CLASS_VALUE(tag, problem_tag, value_class):
def val_error_invalid_value_class_value(tag, problem_tag, value_class):
return f"'{tag}' has an invalid value portion for value class '{value_class}'"


Expand All @@ -70,15 +70,21 @@ def val_error_tildes_not_supported(source_string, char_index):
return f"Tildes not supported. Replace (a ~ b ~ c) with (a, (b, c)). '{character}' at index {char_index}'"


@hed_tag_error(ValidationErrors.CURLY_BRACE_UNSUPPORTED_HERE, has_sub_tag=True,
@hed_tag_error(ValidationErrors.HED_PLACEHOLDER_OUT_OF_CONTEXT, has_sub_tag=False,
actual_code=ValidationErrors.PLACEHOLDER_INVALID)
def val_error_hed_placeholder_out_of_context(tag):
return f"'{tag}' has a '#' placeholder where it is not allowed or where it should have been replaced with a value."


@hed_tag_error(ValidationErrors.CURLY_BRACE_UNSUPPORTED_HERE, has_sub_tag=False,
actual_code=SidecarErrors.SIDECAR_BRACES_INVALID)
def val_error_CURLY_BRACE_UNSUPPORTED_HERE(tag, problem_tag):
def val_error_curly_brace_unsupported_here(tag, problem_tag):
return (f"Curly braces are only permitted in sidecars, fully wrapping text in place of a tag. "
f"Invalid character '{problem_tag}' in tag '{tag}'")


@hed_error(ValidationErrors.ONSETS_UNORDERED, default_severity=ErrorSeverity.WARNING)
def val_error_ONSETS_UNORDERED():
def val_error_onsets_unordered():
return "Onsets need to be temporally increasing and defined for many downstream tools to work."


Expand All @@ -97,6 +103,17 @@ def val_error_duplicate_group(group):
return f'Repeated group - "{group}"'


@hed_error(ValidationErrors.HED_RESERVED_TAG_REPEATED, actual_code=ValidationErrors.TAG_GROUP_ERROR)
def val_error_duplicate_reserved_tag(tag, group):
return f'Repeated reserved tag "{tag}" or multiple reserved tags in group "{group}"'


@hed_error(ValidationErrors.HED_RESERVED_TAG_GROUP_ERROR, actual_code=ValidationErrors.TAG_GROUP_ERROR)
def val_error_group_for_reserved_tag(group, group_count):
return (f'The number of non-def-expand subgroups for group "{group}" is {group_count}, "'
f'which does not meet reserved tag requirements."')


@hed_error(ValidationErrors.PARENTHESES_MISMATCH)
def val_error_parentheses(opening_parentheses_count, closing_parentheses_count):
return f'Number of opening and closing parentheses are unequal. '\
Expand Down Expand Up @@ -236,12 +253,12 @@ def val_error_def_expand_value_extra(tag):

@hed_tag_error(ValidationErrors.HED_TOP_LEVEL_TAG, actual_code=ValidationErrors.TAG_GROUP_ERROR)
def val_error_top_level_tag(tag):
return f"A tag that must be in a top level group was found in another location. {str(tag)}"
return f'Tag "{tag}" must be in a top level group but was found in another location.'


@hed_tag_error(ValidationErrors.HED_TAG_GROUP_TAG, actual_code=ValidationErrors.TAG_GROUP_ERROR)
def val_error_tag_group_tag(tag):
return f"A tag that must be in a group was found in another location. {str(tag)}"
return f'Tag "{tag}" that must be in a group was found in another location.'


@hed_tag_error(ValidationErrors.HED_MULTIPLE_TOP_TAGS, actual_code=ValidationErrors.TAG_GROUP_ERROR)
Expand All @@ -251,6 +268,11 @@ def val_error_top_level_tags(tag, multiple_tags):
f"Remainder:{str(tags_as_string)}"


@hed_tag_error(ValidationErrors.HED_TAGS_NOT_ALLOWED, actual_code=ValidationErrors.TAG_GROUP_ERROR)
def val_error_tags_in_group_with_reserved(tag, group):
return f'Tag "{tag}" is not allowed with the other tag(s) or Def-expand sub-group in group "{group}"'


@hed_error(ValidationErrors.REQUIRED_TAG_MISSING)
def val_warning_required_prefix_missing(tag_namespace):
return f"Tag with namespace '{tag_namespace}' is required"
Expand All @@ -261,11 +283,6 @@ def val_warning_capitalization(tag):
return f"First word not capitalized or camel case - '{tag}'"


@hed_tag_error(ValidationErrors.UNITS_MISSING, default_severity=ErrorSeverity.WARNING)
def val_warning_default_units_used(tag, default_unit):
return f"Tag '{tag}' expects units, but no units were given."


@hed_error(SidecarErrors.BLANK_HED_STRING)
def sidecar_error_blank_hed_string():
return "No HED string found for Value or Category column."
Expand Down Expand Up @@ -293,12 +310,12 @@ def sidecar_error_unknown_column(column_name):


@hed_error(SidecarErrors.SIDECAR_HED_USED, actual_code=ValidationErrors.SIDECAR_INVALID)
def SIDECAR_HED_USED():
def sidecar_hed_used():
return "'HED' is a reserved name and cannot be used as a sidecar except in expected places."


@hed_error(SidecarErrors.SIDECAR_HED_USED_COLUMN, actual_code=ValidationErrors.SIDECAR_INVALID)
def SIDECAR_HED_USED_COLUMN():
def sidecar_hed_used_column():
return "'HED' is a reserved name and cannot be used as a sidecar column name"


Expand Down Expand Up @@ -384,7 +401,7 @@ def onset_error_inset_before_onset(tag):

@hed_tag_error(TemporalErrors.ONSET_NO_DEF_TAG_FOUND, actual_code=ValidationErrors.TEMPORAL_TAG_ERROR)
def onset_no_def_found(tag):
return f"'{tag}' tag has no def or def-expand tag in string."
return f"'{tag}' tag has no def tag or def-expand group or too many when 1 is required in string."


@hed_tag_error(TemporalErrors.ONSET_TOO_MANY_DEFS, actual_code=ValidationErrors.TEMPORAL_TAG_ERROR)
Expand All @@ -401,7 +418,7 @@ def onset_too_many_groups(tag, tag_list):


@hed_tag_error(TemporalErrors.DURATION_WRONG_NUMBER_GROUPS, actual_code=ValidationErrors.TEMPORAL_TAG_ERROR)
def onset_DURATION_WRONG_NUMBER_GROUPS(tag, tag_list):
def onset_duration_wrong_number_groups(tag, tag_list):
tag_list_strings = [str(a_tag) for a_tag in tag_list]
return f"A duration and/or delay tag '{tag}'should have exactly one child group." \
f"Found {len(tag_list_strings)}: {tag_list_strings}"
Expand All @@ -421,7 +438,7 @@ def onset_wrong_placeholder(tag, has_placeholder):


@hed_tag_error(TemporalErrors.DURATION_HAS_OTHER_TAGS, actual_code=ValidationErrors.TEMPORAL_TAG_ERROR)
def onset_DURATION_HAS_OTHER_TAGS(tag):
def onset_duration_has_other_tags(tag):
return f"Tag '{tag}' should not be grouped with Duration or Delay. Context tags should be in a sub-group."


Expand Down
12 changes: 7 additions & 5 deletions hed/errors/error_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class ValidationErrors:
TAG_REQUIRES_CHILD = 'TAG_REQUIRES_CHILD'
TILDES_UNSUPPORTED = 'TILDES_UNSUPPORTED'
UNITS_INVALID = 'UNITS_INVALID'
UNITS_MISSING = 'UNITS_MISSING'
VERSION_DEPRECATED = 'VERSION_DEPRECATED'
VALUE_INVALID = 'VALUE_INVALID'

Expand All @@ -63,6 +62,8 @@ class ValidationErrors:
HED_DEF_EXPAND_VALUE_MISSING = "HED_DEF_EXPAND_VALUE_MISSING"
HED_DEF_EXPAND_VALUE_EXTRA = "HED_DEF_EXPAND_VALUE_EXTRA"

HED_RESERVED_TAG_REPEATED = 'HED_RESERVED_TAG_REPEATED'
HED_RESERVED_TAG_GROUP_ERROR = 'HED_RESERVED_TAG_GROUP_ERROR'
HED_TAG_REPEATED = 'HED_TAG_REPEATED'
HED_TAG_REPEATED_GROUP = 'HED_TAG_REPEATED_GROUP'

Expand All @@ -71,10 +72,10 @@ class ValidationErrors:
NODE_NAME_EMPTY = 'NODE_NAME_EMPTY'

HED_LIBRARY_UNMATCHED = "HED_LIBRARY_UNMATCHED"

HED_TOP_LEVEL_TAG = "HED_TOP_LEVEL_TAG"
HED_MULTIPLE_TOP_TAGS = "HED_MULTIPLE_TOP_TAGS"
HED_TAG_GROUP_TAG = "HED_TAG_GROUP_TAG"
HED_TAGS_NOT_ALLOWED = "HED_TAGS_NOT_ALLOWED"

HED_GROUP_EMPTY = 'HED_GROUP_EMPTY'
# end internal codes
Expand All @@ -92,7 +93,8 @@ class ValidationErrors:
INVALID_VALUE_CLASS_VALUE = 'INVALID_VALUE_CLASS_VALUE'
INVALID_TAG_CHARACTER = 'invalidTagCharacter'

CURLY_BRACE_UNSUPPORTED_HERE = "CURLY_BRACE_UNSUPPORTED_HERE"
HED_PLACEHOLDER_OUT_OF_CONTEXT = 'HED_PLACEHOLDER_OUT_OF_CONTEXT'
CURLY_BRACE_UNSUPPORTED_HERE = 'CURLY_BRACE_UNSUPPORTED_HERE'
ONSETS_UNORDERED = "ONSETS_UNORDERED"


Expand All @@ -103,9 +105,9 @@ class SidecarErrors:
INVALID_POUND_SIGNS_VALUE = 'invalidNumberPoundSigns'
INVALID_POUND_SIGNS_CATEGORY = 'tooManyPoundSigns'
UNKNOWN_COLUMN_TYPE = 'sidecarUnknownColumn'
SIDECAR_HED_USED_COLUMN = 'SIDECAR_HED_USED_COLUMN'
SIDECAR_HED_USED_COLUMN = 'sidecar_hed_used_column'
SIDECAR_NA_USED = 'SIDECAR_NA_USED'
SIDECAR_HED_USED = 'SIDECAR_HED_USED'
SIDECAR_HED_USED = 'sidecar_hed_used'
SIDECAR_BRACES_INVALID = "SIDECAR_BRACES_INVALID"


Expand Down
5 changes: 3 additions & 2 deletions hed/models/base_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,11 @@ def _load_excel_file(self, file, has_column_names):
loaded_worksheet = self.get_worksheet(self._worksheet_name)
self._dataframe = self._get_dataframe_from_worksheet(loaded_worksheet, has_column_names)
except Exception as e:
raise HedFileError(HedExceptions.INVALID_FILE_FORMAT, f"Failed to load Excel file: {str(e)}", self.name) from e
raise HedFileError(HedExceptions.INVALID_FILE_FORMAT,
f"Failed to load Excel file: {str(e)}", self.name) from e

def _load_text_file(self, file, pandas_header):
""" Load an text file"""
""" Load a text file"""
if isinstance(file, str) and os.path.exists(file) and os.path.getsize(file) == 0:
self._dataframe = pd.DataFrame() # Handle empty file
return
Expand Down
Loading