diff --git a/hed/models/base_input.py b/hed/models/base_input.py index 6b2787bd0..f0c96eaaf 100644 --- a/hed/models/base_input.py +++ b/hed/models/base_input.py @@ -34,11 +34,21 @@ def __init__(self, file, file_type=None, worksheet_name=None, has_column_names=T has_column_names (bool): True if file has column names. This value is ignored if you pass in a pandas dataframe. mapper (ColumnMapper or None): Indicates which columns have HED tags. + See SpreadsheetInput or TabularInput for examples of how to use built-in a ColumnMapper. name (str or None): Optional field for how this file will report errors. allow_blank_names(bool): If True, column names can be blank - Notes: - - See SpreadsheetInput or TabularInput for examples of how to use built-in a ColumnMapper. + :raises HedFileError: + - file is blank + - An invalid dataframe was passed with size 0 + - An invalid extension was provided + - A duplicate or empty column name appears + + :raises OSError: + - Cannot open the indicated file + + :raises KeyError: + - The specified worksheet name does not exist """ if mapper is None: mapper = ColumnMapper() @@ -94,7 +104,6 @@ def reset_mapper(self, new_mapper): Parameters: new_mapper (ColumnMapper): A column mapper to be associated with this base input. - """ self._mapper = new_mapper if not self._mapper: @@ -200,8 +209,10 @@ def to_excel(self, file): file (str or file-like): Location to save this base input. :raises ValueError: - - if empty file object or file cannot be opened. - + - if empty file object was passed + + :raises OSError: + - Cannot open the indicated file """ if not file: raise ValueError("Empty file name or object passed in to BaseInput.save.") @@ -232,6 +243,8 @@ def to_csv(self, file=None): Returns: None or str: None if file is given or the contents as a str if file is None. + :raises OSError: + - Cannot open the indicated file """ dataframe = self._dataframe csv_string_if_filename_none = dataframe.to_csv(file, '\t', index=False, header=self._has_column_names) @@ -272,6 +285,15 @@ def set_cell(self, row_number, column_number, new_string_obj, tag_form="short_ta Notes: Any attribute of a HedTag that returns a string is a valid value of tag_form. + + :raises ValueError: + - There is not a loaded dataframe + + :raises KeyError: + - the indicated row/column does not exist + + :raises AttributeError: + - The indicated tag_form is not an attribute of HedTag """ if self._dataframe is None: raise ValueError("No data frame loaded") @@ -291,6 +313,8 @@ def get_worksheet(self, worksheet_name=None): Notes: If None, returns the first worksheet. + :raises KeyError: + - The specified worksheet name does not exist """ if worksheet_name and self._loaded_workbook: # return self._loaded_workbook.get_sheet_by_name(worksheet_name) diff --git a/hed/models/column_mapper.py b/hed/models/column_mapper.py index 6b5d651cf..fedac6d8f 100644 --- a/hed/models/column_mapper.py +++ b/hed/models/column_mapper.py @@ -26,7 +26,6 @@ def __init__(self, sidecar=None, tag_columns=None, column_prefix_dictionary=None Sidecar column definitions will take precedent if there is a conflict with tag_columns. column_prefix_dictionary (dict): Dictionary with keys that are column numbers/names and values are HED tag prefixes to prepend to the tags in that column before processing. - optional_tag_columns (list): A list of ints or strings containing the columns that contain the HED tags. If the column is otherwise unspecified, convert this column type to HEDTags. warn_on_missing_column (bool): If True, issue mapping warnings on column names that are missing from @@ -89,6 +88,10 @@ def column_prefix_dictionary(self): def get_transformers(self): """ Return the transformers to use on a dataframe + Returns: + tuple(dict, list): + dict({str or int: func}): the functions to use to transform each column + need_categorical(list of int): a list of columns to treat as categoriacl """ final_transformers = {} need_categorical = [] @@ -144,8 +147,8 @@ def _set_sidecar(self, sidecar): Parameters: sidecar (Sidecar or None): the sidecar to use - Returns: - + :raises ValueError: + - A sidecar was prevoiusly set """ if self._sidecar: raise ValueError("Trying to set a second sidecar on a column mapper.") @@ -156,6 +159,11 @@ def _set_sidecar(self, sidecar): @property def sidecar_column_data(self): + """ Pass through to get the sidecar ColumnMetadata + + Returns: + dict({str:ColumnMetadata}): the column metadata defined by this sidecar + """ if self._sidecar: return self._sidecar.column_data @@ -168,7 +176,7 @@ def get_tag_columns(self): Returns: column_identifiers(list): A list of column numbers or names that are ColumnType.HedTags. - 0-based if integer-based, otherwise column name. + 0-based if integer-based, otherwise column name. """ return [column_entry.column_name for number, column_entry in self._final_column_map.items() if column_entry.column_type == ColumnType.HEDTags] diff --git a/hed/models/column_metadata.py b/hed/models/column_metadata.py index 4fa43a6a5..bca22c4cd 100644 --- a/hed/models/column_metadata.py +++ b/hed/models/column_metadata.py @@ -61,6 +61,11 @@ def source_dict(self): return self._source[self.column_name] def get_hed_strings(self): + """ Returns the hed strings for this entry as a series. + + Returns: + hed_strings(pd.Series): the hed strings for this series.(potentially empty) + """ if not self.column_type: return pd.Series(dtype=str) @@ -69,6 +74,15 @@ def get_hed_strings(self): return series def set_hed_strings(self, new_strings): + """ Sets the hed strings for this entry. + + Parameters: + new_strings(pd.Series, dict, or str): The hed strings to set. + This should generally be the return value from get_hed_strings + + Returns: + hed_strings(pd.Series): the hed strings for this series.(potentially empty) + """ if new_strings is None: return False diff --git a/hed/models/def_expand_gather.py b/hed/models/def_expand_gather.py index f34461e46..380079a42 100644 --- a/hed/models/def_expand_gather.py +++ b/hed/models/def_expand_gather.py @@ -93,7 +93,6 @@ def __init__(self, hed_schema, known_defs=None, ambiguous_defs=None, errors=None """ self.hed_schema = hed_schema self.ambiguous_defs = ambiguous_defs if ambiguous_defs else {} - self.ambiguous_defs_new = ambiguous_defs if ambiguous_defs else {} self.errors = errors if errors else {} self.def_dict = DefinitionDict(known_defs, self.hed_schema) diff --git a/hed/models/definition_dict.py b/hed/models/definition_dict.py index ebe1af6f8..0fa6aa743 100644 --- a/hed/models/definition_dict.py +++ b/hed/models/definition_dict.py @@ -12,7 +12,16 @@ class DefinitionDict: """ def __init__(self, def_dicts=None, hed_schema=None): - """ Definitions to be considered a single source. """ + """ Definitions to be considered a single source. + + Parameters: + def_dicts (str or list or DefinitionDict): DefDict or list of DefDicts/strings or + a single string whose definitions should be added. + hed_schema(HedSchema or None): Required if passing strings or lists of strings, unused otherwise. + + :raises TypeError: + - Bad type passed as def_dicts + """ self.defs = {} self._label_tag_name = DefTagNames.DEF_KEY @@ -26,6 +35,9 @@ def add_definitions(self, def_dicts, hed_schema=None): Parameters: def_dicts (list or DefinitionDict): DefDict or list of DefDicts/strings whose definitions should be added. hed_schema(HedSchema or None): Required if passing strings or lists of strings, unused otherwise. + + :raises TypeError: + - Bad type passed as def_dicts """ if not isinstance(def_dicts, list): def_dicts = [def_dicts] @@ -38,7 +50,7 @@ def add_definitions(self, def_dicts, hed_schema=None): for definition in def_dict: self.check_for_definitions(HedString(definition, hed_schema)) else: - print(f"Invalid input type '{type(def_dict)} passed to DefDict. Skipping.") + raise TypeError("Invalid type '{type(def_dict)}' passed to DefinitionDict") def _add_definition(self, def_tag, def_value): if def_tag in self.defs: @@ -59,6 +71,16 @@ def _add_definitions_from_dict(self, def_dict): self._add_definition(def_tag, def_value) def get(self, def_name): + """ Get the definition entry for the definition name. + + Not case-sensitive + + Parameters: + def_name (str): Name of the definition to retrieve. + + Returns: + DefinitionEntry: Definition entry for the requested definition. + """ return self.defs.get(def_name.lower()) def __iter__(self): @@ -68,6 +90,13 @@ def __len__(self): return len(self.defs) def items(self): + """ Returns the dictionary of definitions + + Alias for .defs.items() + + Returns: + def_entries({str: DefinitionEntry}): A list of definitions + """ return self.defs.items() @property @@ -75,19 +104,6 @@ def issues(self): """Returns issues about duplicate definitions.""" return self._issues - def get_def_entry(self, def_name): - """ Get the definition entry for the definition name. - - Parameters: - def_name (str): Name of the definition to retrieve. - - Returns: - DefinitionEntry: Definition entry for the requested definition. - - """ - - return self.defs.get(def_name.lower()) - def check_for_definitions(self, hed_string_obj, error_handler=None): """ Check string for definition tags, adding them to self. @@ -97,7 +113,6 @@ def check_for_definitions(self, hed_string_obj, error_handler=None): Returns: list: List of issues encountered in checking for definitions. Each issue is a dictionary. - """ def_issues = [] for definition_tag, group in hed_string_obj.find_top_level_tags(anchor_tags={DefTagNames.DEFINITION_KEY}): @@ -208,8 +223,8 @@ def _find_group(self, definition_tag, group, error_handler): def _validate_contents(self, definition_tag, group, error_handler): issues = [] if group: - for def_tag in group.find_tags({DefTagNames.DEF_KEY, DefTagNames.DEF_EXPAND_KEY, DefTagNames.DEFINITION_KEY}, recursive=True, - include_groups=0): + def_keys = {DefTagNames.DEF_KEY, DefTagNames.DEF_EXPAND_KEY, DefTagNames.DEFINITION_KEY} + for def_tag in group.find_tags(def_keys, recursive=True, include_groups=0): issues += ErrorHandler.format_error_with_context(error_handler, DefinitionErrors.DEF_TAG_IN_DEFINITION, tag=def_tag, @@ -250,27 +265,6 @@ def construct_def_tag(self, hed_tag): hed_tag._expandable = def_contents hed_tag._expanded = hed_tag.short_base_tag == DefTagNames.DEF_EXPAND_ORG_KEY - def expand_def_tags(self, hed_string_obj): - """ Expands def tags to def-expand tags. - - Parameters: - hed_string_obj (HedString): The hed string to process. - """ - # First see if the "def" is found at all. This covers def and def-expand. - hed_string_lower = hed_string_obj.lower() - if self._label_tag_name not in hed_string_lower: - return [] - - def_issues = [] - # We need to check for labels to expand in ALL groups - for def_tag, def_group in hed_string_obj.find_tags(DefTagNames.DEF_KEY, recursive=True): - def_contents = self._get_definition_contents(def_tag) - if def_contents is not None: - def_tag.short_base_tag = DefTagNames.DEF_EXPAND_ORG_KEY - def_group.replace(def_tag, def_contents) - - return def_issues - def _get_definition_contents(self, def_tag): """ Get the contents for a given def tag. diff --git a/hed/models/definition_entry.py b/hed/models/definition_entry.py index 7c0aa3662..190d8d3d3 100644 --- a/hed/models/definition_entry.py +++ b/hed/models/definition_entry.py @@ -26,6 +26,8 @@ def __init__(self, name, contents, takes_value, source_context): def get_definition(self, replace_tag, placeholder_value=None, return_copy_of_tag=False): """ Return a copy of the definition with the tag expanded and the placeholder plugged in. + Returns None if placeholder_value passed when it doesn't take value, or vice versa. + Parameters: replace_tag (HedTag): The def hed tag to replace with an expanded version placeholder_value (str or None): If present and required, will replace any pound signs @@ -33,12 +35,12 @@ def get_definition(self, replace_tag, placeholder_value=None, return_copy_of_tag return_copy_of_tag(bool): Set to true for validation Returns: - str: The expanded def tag name - HedGroup: The contents of this definition(including the def tag itself) + tuple: + str: The expanded def tag name + HedGroup: The contents of this definition(including the def tag itself) :raises ValueError: - - If a placeholder_value is passed, but this definition doesn't have a placeholder. - + - Something internally went wrong with finding the placeholder tag. This should not be possible. """ if self.takes_value == (placeholder_value is None): return None, [] @@ -49,7 +51,7 @@ def get_definition(self, replace_tag, placeholder_value=None, return_copy_of_tag name = self.name if self.contents: output_group = self.contents - if placeholder_value: + if placeholder_value is not None: output_group = copy.deepcopy(self.contents) placeholder_tag = output_group.find_placeholder_tag() if not placeholder_tag: @@ -64,4 +66,4 @@ def get_definition(self, replace_tag, placeholder_value=None, return_copy_of_tag return f"{DefTagNames.DEF_EXPAND_ORG_KEY}/{name}", output_contents def __str__(self): - return str(self.contents) \ No newline at end of file + return str(self.contents) diff --git a/hed/models/df_util.py b/hed/models/df_util.py index ba378502a..83184a4e9 100644 --- a/hed/models/df_util.py +++ b/hed/models/df_util.py @@ -27,8 +27,9 @@ def get_assembled(tabular_file, sidecar, hed_schema, extra_def_dicts=None, join_ expand_defs: bool Expand any def tags found Returns: - tuple: A list of HedStrings or a list of lists of HedStrings, DefinitionDict - + tuple: + hed_strings(list of HedStrings):A list of HedStrings or a list of lists of HedStrings + def_dict(DefinitionDict): The definitions from this Sidecar """ if isinstance(sidecar, str): sidecar = Sidecar(sidecar) @@ -131,23 +132,11 @@ def _expand_defs(hed_string, hed_schema, def_dict): return str(HedString(hed_string, hed_schema, def_dict).expand_defs()) -def _get_matching_value(tags): - # Filter out values equal to "#" and get unique values - unique_values = set(tag.extension for tag in tags if tag.extension != "#") - if len(unique_values) == 0: - return "#" - - if len(unique_values) > 1: - return None - - return next(iter(unique_values)) - - def process_def_expands(hed_strings, hed_schema, known_defs=None, ambiguous_defs=None): - """ - Processes a list of HED strings according to a given HED schema, using known definitions and ambiguous definitions. + """ Processes a list of HED strings according to a given HED schema, + using known definitions and ambiguous definitions. - Args: + Parameters: hed_strings (list or pd.Series): A list of HED strings to process. hed_schema (HedSchema): The schema to use known_defs (DefinitionDict or list or str), optional): diff --git a/hed/models/hed_group.py b/hed/models/hed_group.py index 10ea9a360..eeacd16db 100644 --- a/hed/models/hed_group.py +++ b/hed/models/hed_group.py @@ -13,10 +13,7 @@ def __init__(self, hed_string="", startpos=None, endpos=None, contents=None): startpos (int or None): Starting index of group(including parentheses) in hed_string. endpos (int or None): Position after the end (including parentheses) in hed_string. contents (list or None): A list of HedTags and/or HedGroups that will be set as the contents of this group. - - Notes: - - contents parameter is mainly used for processing definitions. - + Mostly used during definition expansion. """ self._startpos = startpos self._endpos = endpos @@ -68,6 +65,8 @@ def replace(self, item_to_replace, new_contents): item_to_replace (HedTag or HedGroup): The item to replace must exist or this will raise an error. new_contents (HedTag or HedGroup): Replacement contents. + :raises KeyError: + - item_to_replace does not exist """ if self._original_children is self._children: self._original_children = self._children.copy() @@ -84,24 +83,15 @@ def remove(self, items_to_remove): """ Remove any tags/groups in items_to_remove. Parameters: - items_to_remove (list): List of HedGroups and/or HedTags to remove. + items_to_remove (list): List of HedGroups and/or HedTags to remove by identity. Notes: - Any groups that become empty will also be pruned. - - Identity, not equivalence is used in determining whether to remove. - """ all_groups = self.get_all_groups() self._remove(items_to_remove, all_groups) def _remove(self, items_to_remove, all_groups): - """ Needs to be documented. - - Parameters: - items_to_remove (list): List of HedGroups and/or HedTags to remove. - all_groups (list): List of HedGroups. - - """ empty_groups = [] for remove_child in items_to_remove: for group in all_groups: @@ -329,10 +319,6 @@ def get_as_form(self, tag_attribute): Returns: str: The constructed string after transformation - - Notes: - - The signature of a tag_transformer is str def(HedTag, str). - """ result = ",".join([child.__getattribute__(tag_attribute) if isinstance(child, HedTag) else child.get_as_form(tag_attribute) for child in self.children]) @@ -352,7 +338,6 @@ def find_placeholder_tag(self): Notes: - Assumes a valid HedString with no erroneous "#" characters. - """ for tag in self.get_all_tags(): if tag.is_placeholder(): @@ -364,7 +349,10 @@ def __bool__(self): return bool(self._children) def __eq__(self, other): - """ Test whether other is equal to this object. """ + """ Test whether other is equal to this object. + + Note: This does not account for sorting. Objects must be in the same order to match. + """ if self is other: return True @@ -419,17 +407,16 @@ def find_wildcard_tags(self, search_tags, recursive=False, include_groups=2): search_tags (container): A container of the starts of short tags to search. recursive (bool): If true, also check subgroups. include_groups (0, 1 or 2): Specify return values. + If 0: return a list of the HedTags. + If 1: return a list of the HedGroups containing the HedTags. + If 2: return a list of tuples (HedTag, HedGroup) for the found tags. Returns: list: The contents of the list depends on the value of include_groups. Notes: - - If include_groups is 0, return a list of the HedTags. - - If include_groups is 1, return a list of the HedGroups containing the HedTags. - - If include_groups is 2, return a list of tuples (HedTag, HedGroup) for the found tags. - This can only find identified tags. - By default, definition, def, def-expand, onset, and offset are identified, even without a schema. - """ found_tags = [] if recursive: @@ -486,17 +473,16 @@ def find_exact_tags(self, tags_or_groups, recursive=False, include_groups=1): def find_def_tags(self, recursive=False, include_groups=3): """ Find def and def-expand tags + Parameters: recursive (bool): If true, also check subgroups. include_groups (int, 0, 1, 2, 3): options for return values + If 0: Return only def and def expand tags/. + If 1: Return only def tags and def-expand groups. + If 2: Return only groups containing defs, or def-expand groups. + If 3 or any other value: Return all 3 as a tuple. Returns: list: A list of tuples. The contents depend on the values of the include_group. - Notes: - - The include_groups option controls the tag expansion as follows: - - If 0: Return only def and def expand tags/. - - If 1: Return only def tags and def-expand groups. - - If 2: Return only groups containing defs, or def-expand groups. - - If 3 or any other value: Return all 3 as a tuple. """ from hed.models.definition_dict import DefTagNames if recursive: @@ -527,16 +513,14 @@ def find_tags_with_term(self, term, recursive=False, include_groups=2): Parameters: term (str): A single term to search for. recursive (bool): If true, recursively check subgroups. - include_groups: 0, 1 or 2 + include_groups(0, 1 or 2): Controls return values If 0: Return only tags If 1: Return only groups If 2 or any other value: Return both Returns: list: - """ - found_tags = [] if recursive: groups = self.get_all_groups() diff --git a/hed/models/hed_string.py b/hed/models/hed_string.py index 30b67ee3c..173b67860 100644 --- a/hed/models/hed_string.py +++ b/hed/models/hed_string.py @@ -180,12 +180,11 @@ def split_into_groups(hed_string, hed_schema=None, def_dict=None): list: A list of HedTag and/or HedGroup. :raises ValueError: - - If the string is significantly malformed, such as mismatched parentheses. + - The string is significantly malformed, such as mismatched parentheses. Notes: - The parse tree consists of tag groups, tags, and delimiters. """ - current_tag_group = [[]] input_tags = HedString.split_hed_string(hed_string) @@ -332,19 +331,16 @@ def validate(self, hed_schema, allow_placeholders=True, error_handler=None): def find_top_level_tags(self, anchor_tags, include_groups=2): """ Find top level groups with an anchor tag. + A max of 1 tag located per top level group. + Parameters: anchor_tags (container): A list/set/etc of short_base_tags to find groups by. include_groups (0, 1 or 2): Parameter indicating what return values to include. - + If 0: return only tags. + If 1: return only groups. + If 2 or any other value: return both. Returns: list or tuple: The returned result depends on include_groups: - - If 0: return only tags. - - If 1: return only groups. - - If 2 or any other value: return both. - - Notes: - - A max of 1 tag located per top level group. - """ top_level_tags = [] for group in self.groups(): diff --git a/hed/models/hed_string_group.py b/hed/models/hed_string_group.py index 14e639f51..3171823ce 100644 --- a/hed/models/hed_string_group.py +++ b/hed/models/hed_string_group.py @@ -60,15 +60,13 @@ def children(self): return [child for sub_string in self._children for child in sub_string._children] def remove(self, items_to_remove): - """ Remove any tags/groups in items_to_remove. + """ Remove tags/groups by identity. Parameters: items_to_remove (list): A list of HedGroup and HedTag objects to remove. Notes: - Any groups that become empty will also be pruned. - - This goes by identity, not equivalence. - """ all_groups = [group for sub_group in self._children for group in sub_group.get_all_groups()] self._remove(items_to_remove, all_groups) @@ -85,12 +83,9 @@ def replace(self, item_to_replace, new_contents): item_to_replace (HedTag or HedGroup): The tag to replace. new_contents (HedTag or HedGroup or list): The replacements for the tag. - Notes: - - It tag must exist in this an error is raised. - + :raises KeyError: + - item_to_replace does not exist """ - - # this needs to pass the tag off to the appropriate group replace_sub_string = None for sub_string in self._children: for i, child in enumerate(sub_string.children): diff --git a/hed/models/hed_tag.py b/hed/models/hed_tag.py index 2c17d368a..bfc06abd2 100644 --- a/hed/models/hed_tag.py +++ b/hed/models/hed_tag.py @@ -19,9 +19,8 @@ def __init__(self, hed_string, span=None, hed_schema=None, def_dict=None): span (int, int): The start and end indexes of the tag in the hed_string. hed_schema (HedSchema or None): A convenience parameter for calculating canonical forms on creation. - Notes: - - This does not produce issues and is used primarily for testing. - + :raises ValueError: + - You cannot pass a def_dict without also passing a schema. """ if def_dict and not hed_schema: raise ValueError("Passing a def_dict without also passing a schema is invalid.") @@ -131,11 +130,10 @@ def short_base_tag(self, new_tag_val): new_tag_val (str): The new short_base_tag for this tag. :raises ValueError: - - If tags cannot unidentified. + - If the tag wasn't already identified Note: - Generally this is used to swap def to def-expand. - """ if self._schema_entry: tag_entry = None @@ -159,7 +157,6 @@ def org_base_tag(self): - Warning: This could be empty if the original tag had a name_prefix prepended. e.g. a column where "Label/" is prepended, thus the column value has zero base portion. - Only valid after calling convert_to_canonical_forms. - """ if self._schema_entry: extension_len = len(self._extension_value) diff --git a/hed/models/sidecar.py b/hed/models/sidecar.py index 094edfa69..735ad3f8b 100644 --- a/hed/models/sidecar.py +++ b/hed/models/sidecar.py @@ -67,10 +67,10 @@ def def_dict(self): @property def column_data(self): - """ Generates the list of ColumnMetadata for this sidecar + """ Generates the ColumnMetadata for this sidecar Returns: - list(ColumnMetadata): the list of column metadata defined by this sidecar + dict({str:ColumnMetadata}): the column metadata defined by this sidecar """ return {col_name: ColumnMetadata(name=col_name, source=self.loaded_dict) for col_name in self.loaded_dict} @@ -200,8 +200,8 @@ def extract_definitions(self, hed_schema=None, error_handler=None): """ Gather and validate definitions in metadata. Parameters: - error_handler (ErrorHandler): The error handler to use for context, uses a default one if None. hed_schema (HedSchema or None): The schema to used to identify tags. + error_handler (ErrorHandler or None): The error handler to use for context, uses a default one if None. Returns: DefinitionDict: Contains all the definitions located in the sidecar. @@ -238,7 +238,6 @@ def get_column_refs(self): Returns: column_refs(list): A list of unique column refs found """ - found_vals = set() for column_data in self: if column_data.column_type == ColumnType.Ignore: diff --git a/hed/models/spreadsheet_input.py b/hed/models/spreadsheet_input.py index c3a059bdc..d2bcbc1bd 100644 --- a/hed/models/spreadsheet_input.py +++ b/hed/models/spreadsheet_input.py @@ -30,6 +30,17 @@ def __init__(self, file=None, file_type=None, worksheet_name=None, tag_columns=N It will be a validation issue if column 1 is called "key" in the above example. This means it no longer accepts anything but the value portion only in the columns. + :raises HedFileError: + - file is blank + - An invalid dataframe was passed with size 0 + - An invalid extension was provided + - A duplicate or empty column name appears + + :raises OSError: + - Cannot open the indicated file + + :raises KeyError: + - The specified worksheet name does not exist """ if tag_columns is None: tag_columns = [1] diff --git a/hed/models/tabular_input.py b/hed/models/tabular_input.py index 8a6d5c5f8..b88ed5581 100644 --- a/hed/models/tabular_input.py +++ b/hed/models/tabular_input.py @@ -16,6 +16,18 @@ def __init__(self, file=None, sidecar=None, name=None): file (str or file like): A tsv file to open. sidecar (str or Sidecar): A Sidecar filename or Sidecar name (str): The name to display for this file for error purposes. + + :raises HedFileError: + - file is blank + - An invalid dataframe was passed with size 0 + - An invalid extension was provided + - A duplicate or empty column name appears + + :raises OSError: + - Cannot open the indicated file + + :raises ValueError: + - This file has no column names """ if sidecar and not isinstance(sidecar, Sidecar): sidecar = Sidecar(sidecar) diff --git a/hed/validator/onset_validator.py b/hed/validator/onset_validator.py index 8cac74422..f44b291ba 100644 --- a/hed/validator/onset_validator.py +++ b/hed/validator/onset_validator.py @@ -77,7 +77,7 @@ def _handle_onset_or_offset(self, def_tag, onset_offset_tag): placeholder = def_name[found_slash + 1:] def_name = def_name[:found_slash] - def_entry = self._defs.get_def_entry(def_name) + def_entry = self._defs.get(def_name) if def_entry is None: return ErrorHandler.format_error(OnsetErrors.ONSET_DEF_UNMATCHED, tag=def_tag) if bool(def_entry.takes_value) != bool(placeholder): diff --git a/tests/models/test_definition_dict.py b/tests/models/test_definition_dict.py index eb5490529..61296e638 100644 --- a/tests/models/test_definition_dict.py +++ b/tests/models/test_definition_dict.py @@ -130,8 +130,8 @@ def test_expand_defs(self): definition_string = "(Definition/TestDefPlaceholder/#,(Age/#,Item/TestDef2))" def_dict.check_for_definitions(HedString(definition_string, hed_schema=self.hed_schema)) for key, test_string in test_strings.items(): - hed_string = HedString(test_string, hed_schema=self.hed_schema) - def_dict.expand_def_tags(hed_string) + hed_string = HedString(test_string, hed_schema=self.hed_schema, def_dict=def_dict) + hed_string.expand_defs() self.assertEqual(str(hed_string), expected_results[key]) if __name__ == '__main__': diff --git a/tests/validator/test_def_validator.py b/tests/validator/test_def_validator.py index 7464e985d..bbaf3eb58 100644 --- a/tests/validator/test_def_validator.py +++ b/tests/validator/test_def_validator.py @@ -50,7 +50,7 @@ def test_expand_def_tags_placeholder_invalid(self): test_string = HedString(placeholder_label_def_string_no_placeholder, self.hed_schema) def_issues = def_validator.validate_def_tags(test_string) - def_issues += def_validator.expand_def_tags(test_string) + test_string.expand_defs() self.assertEqual(str(test_string), placeholder_label_def_string_no_placeholder) self.assertTrue(def_issues) @@ -66,7 +66,7 @@ def test_expand_def_tags_placeholder_invalid(self): test_string = HedString(label_def_string_has_invalid_placeholder, self.hed_schema) def_issues = def_validator.validate_def_tags(test_string) - def_issues += def_validator.expand_def_tags(test_string) + test_string.expand_defs() self.assertEqual(str(test_string), label_def_string_has_invalid_placeholder) self.assertTrue(def_issues)