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
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
per-file-ignores =
# Ignore unused import errors in init files
__init__.py: F401
18 changes: 9 additions & 9 deletions hed/errors/error_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def val_error_duplicate_column(column_number, column_name, list_name):


@hed_error(ValidationErrors.DUPLICATE_COLUMN_BETWEEN_SOURCES)
def val_error_duplicate_column(column_number, column_name, list_names):
def val_error_duplicate_column_between_sources(column_number, column_name, list_names):
if column_name:
return f"Found column '{column_name}' at index {column_number} in the following inputs: {list_names}. " \
f"Each entry must be unique."
Expand Down Expand Up @@ -181,7 +181,7 @@ def val_error_sidecar_key_missing(invalid_key, category_keys):

@hed_tag_error(ValidationErrors.HED_DEF_EXPAND_INVALID, actual_code=ValidationErrors.DEF_EXPAND_INVALID)
def val_error_bad_def_expand(tag, actual_def, found_def):
return f"A data-recording's Def-expand tag does not match the given definition." + \
return f"A data-recording's Def-expand tag does not match the given definition." \
f"Tag: '{tag}'. Actual Def: {actual_def}. Found Def: {found_def}"


Expand Down Expand Up @@ -292,7 +292,7 @@ def sidecar_na_used(column_name):

@hed_tag_error(DefinitionErrors.DEF_TAG_IN_DEFINITION, actual_code=ValidationErrors.DEFINITION_INVALID)
def def_error_def_tag_in_definition(tag, def_name):
return f"Invalid tag {tag} found in definition for {def_name}. " +\
return f"Invalid tag {tag} found in definition for {def_name}. " \
f"Def, Def-expand, and Definition tags cannot be in definitions."


Expand All @@ -302,13 +302,13 @@ def def_error_no_group_tags(def_name):


@hed_error(DefinitionErrors.WRONG_NUMBER_GROUPS, actual_code=ValidationErrors.DEFINITION_INVALID)
def def_error_wrong_group_tags(def_name, tag_list):
def def_error_wrong_number_groups(def_name, tag_list):
tag_list_strings = [str(tag) for tag in tag_list]
return f"Too many group tags found in definition for {def_name}. Expected 1, found: {tag_list_strings}"


@hed_error(DefinitionErrors.WRONG_NUMBER_TAGS, actual_code=ValidationErrors.DEFINITION_INVALID)
def def_error_wrong_group_tags(def_name, tag_list):
def def_error_wrong_number_tags(def_name, tag_list):
tag_list_strings = [str(tag) for tag in tag_list]
return f"Too many tags found in definition for {def_name}. Expected 1, found: {tag_list_strings}"

Expand Down Expand Up @@ -336,7 +336,7 @@ def def_error_no_takes_value(def_name, placeholder_tag):


@hed_tag_error(DefinitionErrors.BAD_PROP_IN_DEFINITION, actual_code=ValidationErrors.DEFINITION_INVALID)
def def_error_no_takes_value(tag, def_name):
def def_error_bad_prop_in_definition(tag, def_name):
return f"Tag '{str(tag)}' in Definition '{def_name}' has has a the unique or required attribute."


Expand Down Expand Up @@ -379,13 +379,13 @@ def onset_too_many_defs(tag, tag_list):
@hed_tag_error(OnsetErrors.ONSET_WRONG_NUMBER_GROUPS, actual_code=ValidationErrors.ONSET_OFFSET_INSET_ERROR)
def onset_too_many_groups(tag, tag_list):
tag_list_strings = [str(a_tag) for a_tag in tag_list]
return f"An onset tag should have at most 2 sibling nodes, an offset tag should have 1. " +\
return f"An onset tag should have at most 2 sibling nodes, an offset tag should have 1. " \
f"Found {len(tag_list_strings)}: {tag_list_strings}"


@hed_tag_error(OnsetErrors.ONSET_TAG_OUTSIDE_OF_GROUP, actual_code=ValidationErrors.ONSET_OFFSET_INSET_ERROR)
def onset_wrong_type_tag(tag, def_tag):
return f"Onset def tag '{def_tag}' has an improper sibling tag '{tag}'. All onset context tags must be " + \
return f"Onset def tag '{def_tag}' has an improper sibling tag '{tag}'. All onset context tags must be " \
f"in a single group together."


Expand Down Expand Up @@ -413,5 +413,5 @@ def nested_column_ref(column_name, ref_column):


@hed_error(ColumnErrors.MALFORMED_COLUMN_REF, actual_code=SidecarErrors.SIDECAR_BRACES_INVALID)
def nested_column_ref(column_name, index, symbol):
def malformed_column_ref(column_name, index, symbol):
return f"Column {column_name} has a malformed column reference. Improper symbol {symbol} found at index {index}."
4 changes: 2 additions & 2 deletions hed/errors/error_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ def wrapper(tag, *args, severity=default_severity, **kwargs):


# Import after hed_error decorators are defined.
from hed.errors import error_messages
from hed.errors import schema_error_messages
from hed.errors import error_messages # noqa:E402
from hed.errors import schema_error_messages # noqa:E402

# Intentional to make sure tools don't think the import is unused
error_messages.mark_as_used = True
Expand Down
1 change: 0 additions & 1 deletion hed/models/base_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from hed.models.column_mapper import ColumnMapper
from hed.errors.exceptions import HedFileError, HedExceptions
from hed.errors.error_reporter import ErrorHandler
import pandas as pd


Expand Down
1 change: 0 additions & 1 deletion hed/models/column_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Mapping of a base input file columns into HED tags.
"""
from hed.models.column_metadata import ColumnMetadata, ColumnType
from hed.models.sidecar import Sidecar
from hed.errors.error_reporter import ErrorHandler
from hed.errors.error_types import ValidationErrors
from hed.models.definition_dict import DefinitionDict
Expand Down
2 changes: 1 addition & 1 deletion hed/models/def_expand_gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def _handle_ambiguous_definition(self, def_tag, def_expand_group):
takes_value=True,
source_context=[])
del self.ambiguous_defs[def_tag_name.lower()]
except ValueError as e:
except ValueError:
for ambiguous_def in these_defs.placeholder_defs:
self.errors.setdefault(def_tag_name.lower(), []).append(ambiguous_def)
del self.ambiguous_defs[def_tag_name.lower()]
Expand Down
3 changes: 0 additions & 3 deletions hed/models/df_util.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
""" Utilities for assembly and conversion of HED strings to different forms. """
from functools import partial
import pandas as pd
from hed.models.tabular_input import TabularInput
from hed.models.hed_string import HedString
from hed.models.definition_dict import DefinitionDict


def get_assembled(tabular_file, hed_schema, extra_def_dicts=None, defs_expanded=True):
Expand Down Expand Up @@ -120,7 +118,6 @@ def process_def_expands(hed_strings, hed_schema, known_defs=None, ambiguous_defs
Returns:
tuple: A tuple containing the DefinitionDict, ambiguous definitions, and errors.
"""

from hed.models.def_expand_gather import DefExpandGatherer
def_gatherer = DefExpandGatherer(hed_schema, known_defs, ambiguous_defs)
return def_gatherer.process_def_expands(hed_strings)
Expand Down
4 changes: 2 additions & 2 deletions hed/models/query_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_query_handlers(queries, query_names=None):

"""
if not queries:
return None, None, [f"EmptyQueries: The queries list must not be empty"]
return None, None, ["EmptyQueries: The queries list must not be empty"]
elif isinstance(queries, str):
queries = [queries]
expression_parsers = [None] * len(queries)
Expand All @@ -35,7 +35,7 @@ def get_query_handlers(queries, query_names=None):
for index, query in enumerate(queries):
try:
expression_parsers[index] = QueryHandler(query)
except Exception as ex:
except Exception:
issues.append(f"[BadQuery {index}]: {query} cannot be parsed")
return expression_parsers, query_names, issues

Expand Down
5 changes: 2 additions & 3 deletions hed/models/sidecar.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ def load_sidecar_file(self, file):

:raises HedFileError:
- If the file was not found or could not be parsed into JSON.

"""
if not file:
return {}
Expand All @@ -144,7 +143,7 @@ def load_sidecar_files(self, files):

:raises HedFileError:
- If the file was not found or could not be parsed into JSON.

"""
if not files:
return {}
Expand All @@ -165,7 +164,7 @@ def validate(self, hed_schema, extra_def_dicts=None, name=None, error_handler=No
extra_def_dicts(list or DefinitionDict): Extra def dicts in addition to sidecar.
name(str): The name to report this sidecar as.
error_handler (ErrorHandler): Error context to use. Creates a new one if None.

Returns:
issues (list of dict): A list of issues associated with each level in the HED string.
"""
Expand Down
4 changes: 2 additions & 2 deletions hed/models/spreadsheet_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, file=None, file_type=None, worksheet_name=None, tag_columns=N

Parameters:
file (str or file like): An xlsx/tsv file to open or a File object.
file_type (str or None): ".xlsx" for Excel, ".tsv" or ".txt" for tsv. data.
file_type (str or None): ".xlsx" for Excel, ".tsv" or ".txt" for tsv. data.
worksheet_name (str or None): The name of the Excel workbook worksheet that contains the HED tags.
Not applicable to tsv files. If omitted for Excel, the first worksheet is assumed.
tag_columns (list): A list of ints or strs containing the columns that contain the HED tags.
Expand All @@ -24,7 +24,7 @@ def __init__(self, file=None, file_type=None, worksheet_name=None, tag_columns=N
values are HED tag prefixes to prepend to the tags in that column before processing.

Notes:
- If file is a string, file_type is derived from file and this parameter is ignored.
- If file is a string, file_type is derived from file and this parameter is ignored.
- column_prefix_dictionary may be deprecated/renamed. These are no longer prefixes,
but rather converted to value columns.
e.g. {"key": "Description", 1: "Label/"} will turn into value columns as
Expand Down
2 changes: 1 addition & 1 deletion hed/models/string_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def gather_descriptions(hed_string):

Returns: tuple
description(str): The concatenated values of all description tags.

Side effect:
The input HedString has its description tags removed.

Expand Down
1 change: 0 additions & 1 deletion hed/models/timeseries_input.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
""" A BIDS time series tabular file. """
from hed.models.base_input import BaseInput
from hed.models.sidecar import Sidecar


class TimeseriesInput(BaseInput):
Expand Down
2 changes: 1 addition & 1 deletion hed/schema/hed_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def _find_tag_subfunction(self, tag, working_tag, prefix_tag_adj):

def _validate_remaining_terms(self, tag, working_tag, prefix_tag_adj, current_slash_index):
""" Validates the terms past current_slash_index.

:raises _TagIdentifyError:
- One of the extension terms already exists as a schema term.
"""
Expand Down
20 changes: 9 additions & 11 deletions hed/schema/hed_schema_base.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""
Abstract base class for HedSchema and HedSchemaGroup, showing the common functionality
"""

from hed.errors import ErrorHandler
from hed.schema.hed_schema_constants import HedSectionKey
from abc import ABC, abstractmethod

Expand Down Expand Up @@ -34,7 +32,7 @@ def get_schema_versions(self):
Returns:
list: The complete version of this schema including library name and namespace.
"""
raise NotImplemented("This function must be implemented in the baseclass")
raise NotImplementedError("This function must be implemented in the baseclass")

@abstractmethod
def get_formatted_version(self):
Expand All @@ -43,7 +41,7 @@ def get_formatted_version(self):
Returns:
str: The complete version of this schema including library name and namespace.
"""
raise NotImplemented("This function must be implemented in the baseclass")
raise NotImplementedError("This function must be implemented in the baseclass")

@abstractmethod
def schema_for_namespace(self, namespace):
Expand All @@ -55,7 +53,7 @@ def schema_for_namespace(self, namespace):
Returns:
HedSchema or None: The specific schema for this library name namespace if exists.
"""
raise NotImplemented("This function must be implemented in the baseclass")
raise NotImplementedError("This function must be implemented in the baseclass")

@property
@abstractmethod
Expand All @@ -65,7 +63,7 @@ def valid_prefixes(self):
Returns:
prefixes(list of str): A list of strings representing valid prefixes for this group.
"""
raise NotImplemented("This function must be implemented in the baseclass")
raise NotImplementedError("This function must be implemented in the baseclass")

@abstractmethod
def get_tags_with_attribute(self, attribute, key_class=HedSectionKey.Tags):
Expand All @@ -81,7 +79,7 @@ def get_tags_with_attribute(self, attribute, key_class=HedSectionKey.Tags):
Notes:
- The result is cached so will be fast after first call.
"""
raise NotImplemented("This function must be implemented in the baseclass")
raise NotImplementedError("This function must be implemented in the baseclass")

# todo: maybe tweak this API so you don't have to pass in library namespace?
@abstractmethod
Expand All @@ -98,7 +96,7 @@ def get_tag_entry(self, name, key_class=HedSectionKey.Tags, schema_namespace="")
Returns:
HedSchemaEntry: The schema entry for the given tag.
"""
raise NotImplemented("This function must be implemented in the baseclass")
raise NotImplementedError("This function must be implemented in the baseclass")

@abstractmethod
def find_tag_entry(self, tag, schema_namespace=""):
Expand All @@ -116,11 +114,11 @@ def find_tag_entry(self, tag, schema_namespace=""):
Notes:
Works left to right (which is mostly relevant for errors).
"""
raise NotImplemented("This function must be implemented in the baseclass")
raise NotImplementedError("This function must be implemented in the baseclass")

@abstractmethod
def __eq__(self, other):
raise NotImplemented("This function must be implemented in the baseclass")
raise NotImplementedError("This function must be implemented in the baseclass")

@abstractmethod
def check_compliance(self, check_for_warnings=True, name=None, error_handler=None):
Expand All @@ -135,4 +133,4 @@ def check_compliance(self, check_for_warnings=True, name=None, error_handler=Non
Returns:
list: A list of all warnings and errors found in the file. Each issue is a dictionary.
"""
raise NotImplemented("This function must be implemented in the baseclass")
raise NotImplementedError("This function must be implemented in the baseclass")
1 change: 0 additions & 1 deletion hed/schema/hed_schema_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class HedKey:
IsInheritedProperty = 'isInheritedProperty'



VERSION_ATTRIBUTE = 'version'
LIBRARY_ATTRIBUTE = 'library'
WITH_STANDARD_ATTRIBUTE = "withStandard"
Expand Down
7 changes: 3 additions & 4 deletions hed/schema/hed_schema_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
from hed.schema.hed_schema_constants import HedKey

import inflect
import copy


pluralize = inflect.engine()
pluralize.defnoun("hertz", "hertz")
Expand Down Expand Up @@ -169,7 +167,7 @@ def finalize_entry(self, schema):
self.units = {unit_entry.name: unit_entry for unit_entry in self._units}
derivative_units = {}
for unit_entry in self.units.values():
derivative_units.update({key:unit_entry for key in unit_entry.derivative_units.keys()})
derivative_units.update({key: unit_entry for key in unit_entry.derivative_units.keys()})

self.derivative_units = derivative_units

Expand All @@ -180,6 +178,7 @@ def __eq__(self, other):
return False
return True


class UnitEntry(HedSchemaEntry):
""" A single unit entry with modifiers in the HedSchema. """
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -215,7 +214,7 @@ def _get_conversion_factor(self, modifier_entry):
base_factor = float(self.attributes.get(HedKey.ConversionFactor, "1.0").replace("^", "e"))
if modifier_entry:
modifier_factor = float(modifier_entry.attributes.get(HedKey.ConversionFactor, "1.0").replace("^", "e"))
except (ValueError, AttributeError) as e:
except (ValueError, AttributeError):
pass # Just default to 1.0
return base_factor * modifier_factor

Expand Down
12 changes: 7 additions & 5 deletions hed/schema/hed_schema_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from hed.schema.schema_io.owl_constants import ext_to_format
from urllib.error import URLError


MAX_MEMORY_CACHE = 40


Expand Down Expand Up @@ -56,7 +55,8 @@ def from_string(schema_string, schema_format=".xml", schema_namespace=None, sche
elif schema_format.endswith(".mediawiki"):
hed_schema = SchemaLoaderWiki.load(schema_as_string=schema_string, schema=schema, name=name)
elif schema_format:
hed_schema = SchemaLoaderOWL.load(schema_as_string=schema_string, schema=schema, file_format=schema_format, name=name)
hed_schema = SchemaLoaderOWL.load(schema_as_string=schema_string, schema=schema, file_format=schema_format,
name=name)
else:
raise HedFileError(HedExceptions.INVALID_EXTENSION, f"Unknown schema extension {schema_format}", filename=name)

Expand Down Expand Up @@ -269,14 +269,15 @@ def load_schema_version(xml_version=None, xml_folder=None):
"""
# Check if we start and end with a square bracket, or double quote. This might be valid json
if xml_version and isinstance(xml_version, str) and \
((xml_version[0], xml_version[-1]) in [('[', ']'), ('"', '"')]):
((xml_version[0], xml_version[-1]) in [('[', ']'), ('"', '"')]):
try:
xml_version = json.loads(xml_version)
except json.decoder.JSONDecodeError as e:
raise HedFileError(HedExceptions.CANNOT_PARSE_JSON, str(e), xml_version) from e
if xml_version and isinstance(xml_version, list):
xml_versions = parse_version_list(xml_version)
schemas = [_load_schema_version(xml_version=version, xml_folder=xml_folder) for version in xml_versions.values()]
schemas = [_load_schema_version(xml_version=version, xml_folder=xml_folder) for version in
xml_versions.values()]
if len(schemas) == 1:
return schemas[0]

Expand Down Expand Up @@ -314,6 +315,7 @@ def parse_version_list(xml_version_list):
filename=None)
out_versions[schema_namespace].append(version)

out_versions = {key: ",".join(value) if not key else f"{key}:" + ",".join(value) for key, value in out_versions.items()}
out_versions = {key: ",".join(value) if not key else f"{key}:" + ",".join(value) for key, value in
out_versions.items()}

return out_versions
Loading