From ba441381cc19a014af49fb045c7576287d0d7153 Mon Sep 17 00:00:00 2001 From: IanCa Date: Mon, 12 Jun 2023 12:42:04 -0500 Subject: [PATCH 1/5] Fix bug in caching library schema --- hed/schema/hed_cache.py | 2 +- tests/schema/test_hed_cache.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hed/schema/hed_cache.py b/hed/schema/hed_cache.py index fbcbf12a1..51c0f9ef4 100644 --- a/hed/schema/hed_cache.py +++ b/hed/schema/hed_cache.py @@ -89,7 +89,7 @@ def get_hed_versions(local_hed_directory=None, library_name=None, get_libraries= if expression_match is not None: version = expression_match.group(3) found_library_name = expression_match.group(2) - if found_library_name != library_name: + if not get_libraries and found_library_name != library_name: continue if found_library_name not in all_hed_versions: all_hed_versions[found_library_name] = [] diff --git a/tests/schema/test_hed_cache.py b/tests/schema/test_hed_cache.py index 8b122fdf0..bf8091b15 100644 --- a/tests/schema/test_hed_cache.py +++ b/tests/schema/test_hed_cache.py @@ -85,7 +85,7 @@ def test_cache_specific_url(self): def test_get_hed_versions_all(self): cached_versions = hed_cache.get_hed_versions(self.hed_cache_dir, get_libraries=True) self.assertIsInstance(cached_versions, dict) - self.assertTrue(len(cached_versions) > 0) + self.assertTrue(len(cached_versions) > 1) def test_get_hed_versions(self): cached_versions = hed_cache.get_hed_versions(self.hed_cache_dir) From c2ba7aafe8004dd18bba678eaa0777b1959251c3 Mon Sep 17 00:00:00 2001 From: Kay Robbins <1189050+VisLab@users.noreply.github.com> Date: Mon, 12 Jun 2023 14:49:09 -0500 Subject: [PATCH 2/5] Updated the docs to experiment --- hed/tools/remodeling/operations/factor_hed_tags_op.py | 6 +++--- hed/tools/remodeling/operations/factor_hed_type_op.py | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/hed/tools/remodeling/operations/factor_hed_tags_op.py b/hed/tools/remodeling/operations/factor_hed_tags_op.py index ee8cf3df1..f3ae8cd2f 100644 --- a/hed/tools/remodeling/operations/factor_hed_tags_op.py +++ b/hed/tools/remodeling/operations/factor_hed_tags_op.py @@ -47,15 +47,15 @@ def __init__(self, parameters): KeyError - If a required parameter is missing. - + | - If an unexpected parameter is provided. TypeError - If a parameter has the wrong type. ValueError - - If the specification is missing a valid operation. - + - If the specification is missing a valid operation. + | - If the length of query names is not empty and not same length as queries. - If there are duplicate query names. diff --git a/hed/tools/remodeling/operations/factor_hed_type_op.py b/hed/tools/remodeling/operations/factor_hed_type_op.py index 0a61974ed..73654bfb8 100644 --- a/hed/tools/remodeling/operations/factor_hed_type_op.py +++ b/hed/tools/remodeling/operations/factor_hed_type_op.py @@ -36,13 +36,14 @@ def __init__(self, parameters): parameters (dict): Actual values of the parameters for the operation. Raises: - KeyError - - If a required parameter is missing. - - If an unexpected parameter is provided. + KeyError + - If a required parameter is missing. + | + - If an unexpected parameter is provided. TypeError - If a parameter has the wrong type. - + ValueError - If the specification is missing a valid operation. From 05efcce6011fbe0af37e88d96fe212bfc1562a50 Mon Sep 17 00:00:00 2001 From: Kay Robbins <1189050+VisLab@users.noreply.github.com> Date: Tue, 13 Jun 2023 08:53:51 -0500 Subject: [PATCH 3/5] Trying out the raises --- .../operations/factor_hed_tags_op.py | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/hed/tools/remodeling/operations/factor_hed_tags_op.py b/hed/tools/remodeling/operations/factor_hed_tags_op.py index f3ae8cd2f..02621b753 100644 --- a/hed/tools/remodeling/operations/factor_hed_tags_op.py +++ b/hed/tools/remodeling/operations/factor_hed_tags_op.py @@ -43,22 +43,17 @@ def __init__(self, parameters): Parameters: parameters (dict): Actual values of the parameters for the operation. - Raises: - - KeyError - - If a required parameter is missing. - | - - If an unexpected parameter is provided. - - TypeError - - If a parameter has the wrong type. + :raises KeyError: + - If a required parameter is missing. + - If an unexpected parameter is provided. - ValueError - - If the specification is missing a valid operation. - | - - If the length of query names is not empty and not same length as queries. + :raises TypeError: + - If a parameter has the wrong type. - - If there are duplicate query names. + :raises ValueError: + - If the specification is missing a valid operation. + - If the length of query names is not empty and not same length as queries. + - If there are duplicate query names. """ super().__init__(self.PARAMS, parameters) From 19d31167b6af48aec28037ea8f6fc65844f56eae Mon Sep 17 00:00:00 2001 From: Kay Robbins <1189050+VisLab@users.noreply.github.com> Date: Tue, 13 Jun 2023 10:10:21 -0500 Subject: [PATCH 4/5] Added the raises directive --- hed/models/base_input.py | 6 ++-- hed/models/definition_entry.py | 4 +-- hed/models/hed_group.py | 4 +-- hed/models/hed_string.py | 4 +-- hed/models/hed_tag.py | 4 +-- hed/models/sidecar.py | 16 ++++++---- hed/schema/hed_schema_group.py | 4 +-- hed/schema/hed_schema_io.py | 16 +++++----- hed/schema/schema_validation_util.py | 8 ++--- hed/tools/analysis/analysis_util.py | 8 ++--- hed/tools/analysis/event_manager.py | 12 +++---- hed/tools/analysis/hed_context_manager.py | 12 +++---- hed/tools/analysis/hed_type_manager.py | 5 +-- hed/tools/analysis/hed_type_values.py | 4 +-- hed/tools/analysis/key_map.py | 12 +++---- hed/tools/bids/bids_file_dictionary.py | 12 +++---- hed/tools/bids/bids_tabular_dictionary.py | 4 +-- hed/tools/remodeling/backup_manager.py | 24 +++++++------- hed/tools/remodeling/cli/run_remodel.py | 11 +++---- .../remodeling/cli/run_remodel_backup.py | 5 ++- .../remodeling/cli/run_remodel_restore.py | 5 ++- hed/tools/remodeling/dispatcher.py | 19 ++++++------ hed/tools/remodeling/operations/base_op.py | 31 +++++++++---------- .../operations/convert_columns_op.py | 15 +++++---- .../remodeling/operations/factor_column_op.py | 15 +++++---- .../operations/factor_hed_tags_op.py | 10 +++--- .../operations/factor_hed_type_op.py | 20 ++++++------ .../operations/merge_consecutive_op.py | 30 ++++++++---------- .../remodeling/operations/number_groups_op.py | 2 +- .../remodeling/operations/remap_columns_op.py | 28 ++++++++--------- .../operations/remove_columns_op.py | 16 +++++----- .../remodeling/operations/remove_rows_op.py | 11 +++---- .../operations/rename_columns_op.py | 16 +++++----- .../operations/reorder_columns_op.py | 16 +++++----- .../remodeling/operations/split_rows_op.py | 20 ++++++------ .../operations/summarize_column_names_op.py | 11 +++---- .../operations/summarize_column_values_op.py | 12 +++---- .../operations/summarize_definitions_op.py | 14 ++++----- .../operations/summarize_hed_tags_op.py | 13 ++++---- .../operations/summarize_hed_type_op.py | 11 +++---- .../operations/summarize_hed_validation_op.py | 13 ++++---- .../summarize_sidecar_from_events_op.py | 11 +++---- hed/tools/util/data_util.py | 19 ++++++------ hed/tools/util/io_util.py | 6 ++-- 44 files changed, 255 insertions(+), 284 deletions(-) diff --git a/hed/models/base_input.py b/hed/models/base_input.py index 65ac75101..6b2787bd0 100644 --- a/hed/models/base_input.py +++ b/hed/models/base_input.py @@ -198,8 +198,10 @@ def to_excel(self, file): Parameters: file (str or file-like): Location to save this base input. - Raises: - ValueError: if empty file object or file cannot be opened. + + :raises ValueError: + - if empty file object or file cannot be opened. + """ if not file: raise ValueError("Empty file name or object passed in to BaseInput.save.") diff --git a/hed/models/definition_entry.py b/hed/models/definition_entry.py index 5d3f09edd..7c0aa3662 100644 --- a/hed/models/definition_entry.py +++ b/hed/models/definition_entry.py @@ -36,8 +36,8 @@ def get_definition(self, replace_tag, placeholder_value=None, return_copy_of_tag 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. + :raises ValueError: + - If a placeholder_value is passed, but this definition doesn't have a placeholder. """ if self.takes_value == (placeholder_value is None): diff --git a/hed/models/hed_group.py b/hed/models/hed_group.py index 37947a89d..9a4af46b1 100644 --- a/hed/models/hed_group.py +++ b/hed/models/hed_group.py @@ -37,8 +37,8 @@ def append(self, tag_or_group): Parameters: tag_or_group (HedTag or HedGroup): The new object to add to this group. - Raises: - ValueError: If a HedGroupFrozen. + :raises ValueError: + If a HedGroupFrozen. """ tag_or_group._parent = self diff --git a/hed/models/hed_string.py b/hed/models/hed_string.py index 7f17df234..30b67ee3c 100644 --- a/hed/models/hed_string.py +++ b/hed/models/hed_string.py @@ -179,8 +179,8 @@ def split_into_groups(hed_string, hed_schema=None, def_dict=None): Returns: list: A list of HedTag and/or HedGroup. - Raises: - ValueError: If the string is significantly malformed, such as mismatched parentheses. + :raises ValueError: + - If the string is significantly malformed, such as mismatched parentheses. Notes: - The parse tree consists of tag groups, tags, and delimiters. diff --git a/hed/models/hed_tag.py b/hed/models/hed_tag.py index 0145a46b7..44f1612dc 100644 --- a/hed/models/hed_tag.py +++ b/hed/models/hed_tag.py @@ -130,8 +130,8 @@ def short_base_tag(self, new_tag_val): Parameters: new_tag_val (str): The new short_base_tag for this tag. - Raises: - ValueError: If tags cannot unidentified. + :raises ValueError: + - If tags cannot unidentified. Note: - Generally this is used to swap def to def-expand. diff --git a/hed/models/sidecar.py b/hed/models/sidecar.py index d48165e59..094edfa69 100644 --- a/hed/models/sidecar.py +++ b/hed/models/sidecar.py @@ -120,8 +120,9 @@ def load_sidecar_file(self, file): Parameters: file (str or FileLike): If a string, this is a filename. Otherwise, it will be parsed as a file-like. - Raises: - HedFileError: If the file was not found or could not be parsed into JSON. + :raises HedFileError: + - If the file was not found or could not be parsed into JSON. + """ if not file: return {} @@ -143,8 +144,10 @@ def load_sidecar_files(self, files): Parameters: files (str or FileLike or list): A string or file-like object representing a JSON file, or a list of such. - Raises: - HedFileError: If the file was not found or could not be parsed into JSON. + + :raises HedFileError: + - If the file was not found or could not be parsed into JSON. + """ if not files: return {} @@ -184,8 +187,9 @@ def _load_json_file(self, fp): Parameters: fp (File-like): The JSON source stream. - Raises: - HedFileError: If the file cannot be parsed. + :raises HedFileError: + - If the file cannot be parsed. + """ try: return json.load(fp) diff --git a/hed/schema/hed_schema_group.py b/hed/schema/hed_schema_group.py index 780c5d7fd..ab2112b7a 100644 --- a/hed/schema/hed_schema_group.py +++ b/hed/schema/hed_schema_group.py @@ -26,8 +26,8 @@ def __init__(self, schema_list): Returns: HedSchemaGroup: the container created. - Raises: - HedFileError: If multiple schemas have the same library prefixes. + :raises HedFileError: + - If multiple schemas have the same library prefixes. """ if len(schema_list) == 0: diff --git a/hed/schema/hed_schema_io.py b/hed/schema/hed_schema_io.py index e274e9e39..07e59dcf5 100644 --- a/hed/schema/hed_schema_io.py +++ b/hed/schema/hed_schema_io.py @@ -22,8 +22,8 @@ def from_string(schema_string, file_type=".xml", schema_namespace=None): Returns: (HedSchema): The loaded schema. - Raises: - HedFileError: If empty string or invalid extension is passed. + :raises HedFileError: + - If empty string or invalid extension is passed. Notes: - The loading is determined by file type. @@ -78,8 +78,8 @@ def load_schema(hed_path=None, schema_namespace=None): Returns: HedSchema: The loaded schema. - Raises: - HedFileError: If there are any fatal issues when loading the schema. + :raises HedFileError: + - If there are any fatal issues when loading the schema. """ if not hed_path: @@ -129,8 +129,8 @@ def _load_schema_version(xml_version=None, xml_folder=None): Returns: HedSchema or HedSchemaGroup: The requested HedSchema object. - Raises: - HedFileError: If the xml_version is not valid. + :raises HedFileError: + - If the xml_version is not valid. Notes: - The library schema files have names of the form HED_(LIBRARY_NAME)_(version).xml. @@ -178,8 +178,8 @@ def load_schema_version(xml_version=None, xml_folder=None): Returns: HedSchema or HedSchemaGroup: The schema or schema group extracted. - Raises: - HedFileError: If the xml_version is not valid. + :raises HedFileError: + - If the xml_version is not valid. Notes: - Loads the latest schema value if an empty version is given (string or list). diff --git a/hed/schema/schema_validation_util.py b/hed/schema/schema_validation_util.py index a1fe1d356..97376d380 100644 --- a/hed/schema/schema_validation_util.py +++ b/hed/schema/schema_validation_util.py @@ -80,8 +80,8 @@ def validate_attributes(attrib_dict, filename): Returns: list: List of issues. Each issue is a dictionary. - Raises: - HedFileError: if invalid or version not found in the dictionary. + :raises HedFileError: + - If invalid or version not found in the dictionary. """ validate_present_attributes(attrib_dict, filename) @@ -111,8 +111,8 @@ def find_rooted_entry(tag_entry, schema, loading_merged): rooted_tag(HedTagEntry or None): The base tag entry from the standard schema Returns None if this tag isn't rooted - Raises: - HedValueError: Raises if the tag doesn't exist or similar + :raises HedValueError: + - If the tag doesn't exist or similar """ rooted_tag = tag_entry.has_attribute(constants.HedKey.Rooted, return_value=True) diff --git a/hed/tools/analysis/analysis_util.py b/hed/tools/analysis/analysis_util.py index aa13f288d..343ff80cc 100644 --- a/hed/tools/analysis/analysis_util.py +++ b/hed/tools/analysis/analysis_util.py @@ -55,8 +55,8 @@ def get_expression_parsers(queries, query_names=None): Returns: DataFrame - containing the search strings - Raises: - ValueError - if query names are invalid or duplicated. + :raises ValueError: + - If query names are invalid or duplicated. """ expression_parsers = [] @@ -93,8 +93,8 @@ def search_strings(hed_strings, queries, query_names=None): Returns: DataFrame - containing the factor vectors with results of the queries - Raises: - ValueError - if query names are invalid or duplicated. + :raises ValueError: + - If query names are invalid or duplicated. """ diff --git a/hed/tools/analysis/event_manager.py b/hed/tools/analysis/event_manager.py index 1f1a1acea..58770a1e2 100644 --- a/hed/tools/analysis/event_manager.py +++ b/hed/tools/analysis/event_manager.py @@ -15,8 +15,8 @@ def __init__(self, data, schema): data (TabularInput): A tabular input file. schema (HedSchema): A HED schema - Raises: - HedFileError: if there are any unmatched offsets. + :raises HedFileError: + - if there are any unmatched offsets. """ @@ -46,8 +46,8 @@ def iter_context(self): def _create_event_list(self): """ Create a list of events of extended duration. - Raises: - HedFileError: If the hed_strings contain unmatched offsets. + :raises HedFileError: + - If the hed_strings contain unmatched offsets. """ @@ -107,8 +107,8 @@ def _update_onset_list(self, group, onset_dict, event_index): onset_dict (dict): A dictionary of OnsetGroup objects that keep track of span of an event. event_index (int): The event number in the list. - Raises: - HedFileError if an unmatched offset is encountered. + :raises HedFileError: + - if an unmatched offset is encountered. Notes: - Modifies onset_dict and onset_list. diff --git a/hed/tools/analysis/hed_context_manager.py b/hed/tools/analysis/hed_context_manager.py index 1cee65138..ebf053d2f 100644 --- a/hed/tools/analysis/hed_context_manager.py +++ b/hed/tools/analysis/hed_context_manager.py @@ -27,8 +27,8 @@ def __init__(self, hed_strings, hed_schema): hed_strings (list): A list of HedString objects to be managed. hed_schema (HedSchema): A HedSchema - Raises: - HedFileError: if there are any unmatched offsets. + :raises HedFileError: + - If there are any unmatched offsets. Notes: The constructor has the side-effect of splitting each element of the hed_strings list into two @@ -69,8 +69,8 @@ def iter_context(self): def _create_onset_list(self): """ Create a list of events of extended duration. - Raises: - HedFileError: If the hed_strings contain unmatched offsets. + :raises HedFileError: + - If the hed_strings contain unmatched offsets. """ @@ -122,8 +122,8 @@ def _update_onset_list(self, group, onset_dict, event_index, is_offset=False): event_index (int): The event number in the list. is_offset (bool): True if processing an offset. - Raises: - HedFileError if an unmatched offset is encountered. + :raises HedFileError: + - If an unmatched offset is encountered. Notes: - Modifies onset_dict and onset_list. diff --git a/hed/tools/analysis/hed_type_manager.py b/hed/tools/analysis/hed_type_manager.py index 31e4794fd..43ff826e8 100644 --- a/hed/tools/analysis/hed_type_manager.py +++ b/hed/tools/analysis/hed_type_manager.py @@ -16,8 +16,9 @@ def __init__(self, hed_strings, hed_schema, definitions): hed_schema (HedSchema or HedSchemaGroup): The HED schema to use for processing. definitions (dict): A dictionary of DefinitionEntry objects. - Raises: - HedFileError: On errors such as unmatched onsets or missing definitions. + :raises HedFileError: + - On errors such as unmatched onsets or missing definitions. + """ self.definitions = definitions diff --git a/hed/tools/analysis/hed_type_values.py b/hed/tools/analysis/hed_type_values.py index ceb0d954e..3190d0bf4 100644 --- a/hed/tools/analysis/hed_type_values.py +++ b/hed/tools/analysis/hed_type_values.py @@ -19,8 +19,8 @@ def __init__(self, context_manager, definitions, name, type_tag="condition-varia name (str): Name of the tabular file as a unique identifier. type_tag (str): Lowercase short form of the tag to be managed. - Raises: - HedFileError: On errors such as unmatched onsets or missing definitions. + :raises HedFileError: + - On errors such as unmatched onsets or missing definitions. """ self.name = name diff --git a/hed/tools/analysis/key_map.py b/hed/tools/analysis/key_map.py index ab5536045..72822add0 100644 --- a/hed/tools/analysis/key_map.py +++ b/hed/tools/analysis/key_map.py @@ -63,8 +63,8 @@ def make_template(self, additional_cols=None): Returns: DataFrame: A dataframe containing the template. - Raises: - HedFileError: If additional columns are not disjoint from the key columns. + :raises HedFileError: + - If additional columns are not disjoint from the key columns. Notes: - The template consists of the unique key columns in this map plus additional columns. @@ -90,8 +90,8 @@ def remap(self, data): - DataFrame: New dataframe with columns remapped. - list: List of row numbers that had no correspondence in the mapping. - Raises: - HedFileError: If data is missing some of the key columns. + :raises HedFileError: + - If data is missing some of the key columns. """ @@ -145,8 +145,8 @@ def update(self, data, allow_missing=True, keep_counts=True): Returns: list: The indices of duplicates. - Raises: - HedFileError: If there are missing keys and allow_missing is False. + :raises HedFileError: + - If there are missing keys and allow_missing is False. """ df = get_new_dataframe(data) diff --git a/hed/tools/bids/bids_file_dictionary.py b/hed/tools/bids/bids_file_dictionary.py index 845b69643..b5baac0bc 100644 --- a/hed/tools/bids/bids_file_dictionary.py +++ b/hed/tools/bids/bids_file_dictionary.py @@ -20,8 +20,8 @@ def __init__(self, collection_name, files, entities=('sub', 'ses', 'task', 'run' files (list or dict): Full paths of files to include. entities (tuple): Entity names to use in creating the keys. - Raises: - HedFileError: If files has inappropriate values. + :raises HedFileError: + - If files has inappropriate values. Notes: - This function is used for cross listing BIDS style files for different studies. @@ -117,8 +117,8 @@ def make_dict(self, files, entities): Returns: dict: A dictionary whose keys are entity keys and values are BidsFile objects. - Raises: - HedFileError: If incorrect format is passed or something not recognizable as a Bids file. + :raises HedFileError: + - If incorrect format is passed or something not recognizable as a Bids file. """ file_dict = {} @@ -244,8 +244,8 @@ def _correct_file(cls, the_file): Returns: BidsFile: Either the original file or a newly created BidsTabularFile. - Raises: - HedFileError: If the_file isn't str or BidsFile. + :raises HedFileError: + - If the_file isn't str or BidsFile. """ if isinstance(the_file, str): diff --git a/hed/tools/bids/bids_tabular_dictionary.py b/hed/tools/bids/bids_tabular_dictionary.py index e784ae4d1..c1c57fb86 100644 --- a/hed/tools/bids/bids_tabular_dictionary.py +++ b/hed/tools/bids/bids_tabular_dictionary.py @@ -190,8 +190,8 @@ def _correct_file(cls, the_file): Returns: BidsTabularFile: Either the original file or a newly created BidsTabularFile. - Raises: - HedFileError: If the_file isn't str or BidsTabularFile. + :raises HedFileError: + - If the_file isn't str or BidsTabularFile. """ if isinstance(the_file, str): diff --git a/hed/tools/remodeling/backup_manager.py b/hed/tools/remodeling/backup_manager.py index d98b77c0d..3402fae28 100644 --- a/hed/tools/remodeling/backup_manager.py +++ b/hed/tools/remodeling/backup_manager.py @@ -20,9 +20,9 @@ def __init__(self, data_root, backups_root=None): Parameters: data_root (str): Full path of the root of the data directory. backups_root (str or None): Full path to the root where backups subdirectory is located. - Raises: - - HedFileError: - - If the data_root does not correspond to a real directory. + + :raises HedFileError: + - If the data_root does not correspond to a real directory. """ if not os.path.isdir(data_root): @@ -47,12 +47,11 @@ def create_backup(self, file_list, backup_name=None, verbose=False): Returns: bool: True if the backup was successful. False if a backup of that name already exists. - Raises: - HedFileError - - For missing or incorrect files. + :raises HedFileError: + - For missing or incorrect files. - OS-related error - - OS-related error when file copying occurs. + :raises OS-related error: + - OS-related error when file copying occurs. """ if not backup_name: @@ -108,8 +107,8 @@ def get_backup_files(self, backup_name, original_paths=False): Returns: list: Full paths of the original files backed (original_paths=True) or the paths in the backup. - Raises: - HedFileError - if not backup named backup_name exists. + :raises HedFileError: + - If not backup named backup_name exists. """ @@ -163,8 +162,9 @@ def restore_backup(self, backup_name=DEFAULT_BACKUP_NAME, task_names=[], verbose def _get_backups(self): """ Set the manager's backup-dictionary based on backup directory contents. - Raises: - HedFileError - if a backup is inconsistent for any reason. + :raises HedFileError: + - If a backup is inconsistent for any reason. + """ backups = {} for backup in os.listdir(self.backups_path): diff --git a/hed/tools/remodeling/cli/run_remodel.py b/hed/tools/remodeling/cli/run_remodel.py index 0ba6a9262..47e8333d6 100644 --- a/hed/tools/remodeling/cli/run_remodel.py +++ b/hed/tools/remodeling/cli/run_remodel.py @@ -64,8 +64,8 @@ def parse_arguments(arg_list=None): Object: Argument object List: A list of parsed operations (each operation is a dictionary). - Raises: - ValueError - If the operations were unable to be correctly parsed. + :raises ValueError: + - If the operations were unable to be correctly parsed. """ parser = get_parser() @@ -150,10 +150,9 @@ def main(arg_list=None): arg_list (list or None): Called with value None when called from the command line. Otherwise, called with the command-line parameters as an argument list. - Raises: - HedFileError - - if the data root directory does not exist. - - if the specified backup does not exist. + :raises HedFileError: + - if the data root directory does not exist. + - if the specified backup does not exist. """ args, operations = parse_arguments(arg_list) diff --git a/hed/tools/remodeling/cli/run_remodel_backup.py b/hed/tools/remodeling/cli/run_remodel_backup.py index 40664f138..5bed59e4c 100644 --- a/hed/tools/remodeling/cli/run_remodel_backup.py +++ b/hed/tools/remodeling/cli/run_remodel_backup.py @@ -44,9 +44,8 @@ def main(arg_list=None): arg_list (list or None): Called with value None when called from the command line. Otherwise, called with the command-line parameters as an argument list. - Raises: - HedFileError - - if the specified backup already exists. + :raises HedFileError: + - If the specified backup already exists. """ diff --git a/hed/tools/remodeling/cli/run_remodel_restore.py b/hed/tools/remodeling/cli/run_remodel_restore.py index 79b136805..7f21188d7 100644 --- a/hed/tools/remodeling/cli/run_remodel_restore.py +++ b/hed/tools/remodeling/cli/run_remodel_restore.py @@ -33,9 +33,8 @@ def main(arg_list=None): arg_list (list or None): Called with value None when called from the command line. Otherwise, called with the command-line parameters as an argument list. - Raises: - HedFileError - - if the specified backup does not exist. + :raises HedFileError: + - if the specified backup does not exist. """ parser = get_parser() diff --git a/hed/tools/remodeling/dispatcher.py b/hed/tools/remodeling/dispatcher.py index 8060fabb5..ad033a5b5 100644 --- a/hed/tools/remodeling/dispatcher.py +++ b/hed/tools/remodeling/dispatcher.py @@ -25,12 +25,12 @@ def __init__(self, operation_list, data_root=None, data_root (str or None): Root directory for the dataset. If none, then backups are not made. hed_versions (str, list, HedSchema, or HedSchemaGroup): The HED schema. - Raises: - HedFileError - - If the specified backup does not exist. + :raises HedFileError: + - If the specified backup does not exist. + + :raises ValueError: + - If any of the operations cannot be parsed correctly. - - ValueError: - - If any of the operations cannot be parsed correctly. """ self.data_root = data_root self.backup_name = backup_name @@ -89,9 +89,8 @@ def get_data_file(self, file_designator): Returns: DataFrame: DataFrame after reading the path. - Raises: - HedFileError - - If a valid file cannot be found. + :raises HedFileError: + - If a valid file cannot be found. Notes: - If a string is passed and there is a backup manager, @@ -122,8 +121,8 @@ def get_summary_save_dir(self): Returns: str: the data_root + remodeling summary path - Raises: - HedFileError if this dispatcher does not have a data_root. + :raises HedFileError: + - If this dispatcher does not have a data_root. """ diff --git a/hed/tools/remodeling/operations/base_op.py b/hed/tools/remodeling/operations/base_op.py index 4f04f6397..a524dca26 100644 --- a/hed/tools/remodeling/operations/base_op.py +++ b/hed/tools/remodeling/operations/base_op.py @@ -15,16 +15,15 @@ def __init__(self, op_spec, parameters): op_spec (dict): Specification for required and optional parameters. parameters (dict): Actual values of the parameters for the operation. - Raises: - KeyError - - If a required parameter is missing. - - If an unexpected parameter is provided. + :raises KeyError: + - If a required parameter is missing. + - If an unexpected parameter is provided. - TypeError - - If a parameter has the wrong type. + :raises TypeError: + - If a parameter has the wrong type. - ValueError - - If the specification is missing a valid operation. + :raises ValueError: + - If the specification is missing a valid operation. """ self.operation = op_spec.get("operation", "") @@ -40,14 +39,12 @@ def check_parameters(self, parameters): Parameters: parameters (dict): Dictionary of parameters for this operation. - Raises: + :raises KeyError: + - If a required parameter is missing. + - If an unexpected parameter is provided. - KeyError - - If a required parameter is missing. - - If an unexpected parameter is provided. - - TypeError - - If a parameter has the wrong type. + :raises TypeError: + - If a parameter has the wrong type. """ @@ -90,8 +87,8 @@ def _check_list_type(param_value, param_type): param_value (any): The value to be checked. param_type (any): Class to check the param_value against. - Raises: - TypeError: If param_value is not an instance of param_type. + :raises TypeError: + - If param_value is not an instance of param_type. """ diff --git a/hed/tools/remodeling/operations/convert_columns_op.py b/hed/tools/remodeling/operations/convert_columns_op.py index ae383a1e4..e98a8cce5 100644 --- a/hed/tools/remodeling/operations/convert_columns_op.py +++ b/hed/tools/remodeling/operations/convert_columns_op.py @@ -31,16 +31,15 @@ def __init__(self, parameters): Parameters: parameters (dict): Parameter values for required and optional parameters. - Raises: - KeyError - - If a required parameter is missing. - - If an unexpected parameter is provided. + :raises KeyError: + - If a required parameter is missing. + - If an unexpected parameter is provided. - TypeError - - If a parameter has the wrong type. + :raises TypeError: + - If a parameter has the wrong type. - ValueError - - If convert_to is not one of the allowed values. + :raises ValueError: + - If convert_to is not one of the allowed values. """ super().__init__(self.PARAMS, parameters) diff --git a/hed/tools/remodeling/operations/factor_column_op.py b/hed/tools/remodeling/operations/factor_column_op.py index 173ea2c27..953c327ed 100644 --- a/hed/tools/remodeling/operations/factor_column_op.py +++ b/hed/tools/remodeling/operations/factor_column_op.py @@ -33,16 +33,15 @@ def __init__(self, parameters): Parameters: parameters (dict): Parameter values for required and optional parameters. - Raises: - KeyError - - If a required parameter is missing. - - If an unexpected parameter is provided. + :raises KeyError: + - If a required parameter is missing. + - If an unexpected parameter is provided. - TypeError - - If a parameter has the wrong type. + :raises TypeError: + - If a parameter has the wrong type. - ValueError - - If factor_names is not empty and is not the same length as factor_values. + :raises ValueError: + - If factor_names is not empty and is not the same length as factor_values. """ super().__init__(self.PARAMS, parameters) diff --git a/hed/tools/remodeling/operations/factor_hed_tags_op.py b/hed/tools/remodeling/operations/factor_hed_tags_op.py index 02621b753..675be0b2a 100644 --- a/hed/tools/remodeling/operations/factor_hed_tags_op.py +++ b/hed/tools/remodeling/operations/factor_hed_tags_op.py @@ -60,7 +60,7 @@ def __init__(self, parameters): self.queries = parameters['queries'] self.query_names = parameters['query_names'] self.remove_types = parameters['remove_types'] - self.expression_parsers, self.query_names = get_expression_parsers(self.queries, + self.expression_parsers, self.query_names = get_expression_parsers(self.queries, query_names=parameters['query_names']) def do_op(self, dispatcher, df, name, sidecar=None): @@ -75,10 +75,8 @@ def do_op(self, dispatcher, df, name, sidecar=None): Returns: Dataframe: A new dataframe after processing. - Raises: - - ValueError - - If a name for a new query factor column is already a column. + :raises ValueError: + - If a name for a new query factor column is already a column. """ @@ -91,7 +89,7 @@ def do_op(self, dispatcher, df, name, sidecar=None): raise ValueError("QueryNameAlreadyColumn", f"Query [{query_name}]: is already a column name of the data frame") df_list = [input_data.dataframe] - hed_strings, _ = get_assembled(input_data, sidecar, dispatcher.hed_schema, extra_def_dicts=None, + hed_strings, _ = get_assembled(input_data, sidecar, dispatcher.hed_schema, extra_def_dicts=None, join_columns=True, shrink_defs=False, expand_defs=True) df_factors = search_strings(hed_strings, self.expression_parsers, query_names=self.query_names) if len(df_factors.columns) > 0: diff --git a/hed/tools/remodeling/operations/factor_hed_type_op.py b/hed/tools/remodeling/operations/factor_hed_type_op.py index 73654bfb8..1d5674d7a 100644 --- a/hed/tools/remodeling/operations/factor_hed_type_op.py +++ b/hed/tools/remodeling/operations/factor_hed_type_op.py @@ -35,17 +35,15 @@ def __init__(self, parameters): Parameters: parameters (dict): Actual values of the parameters for the operation. - Raises: - KeyError - - If a required parameter is missing. - | - - If an unexpected parameter is provided. - - TypeError - - If a parameter has the wrong type. - - ValueError - - If the specification is missing a valid operation. + :raises KeyError: + - If a required parameter is missing. + - If an unexpected parameter is provided. + + :raises TypeError: + - If a parameter has the wrong type. + + :raises ValueError: + - If the specification is missing a valid operation. """ super().__init__(self.PARAMS, parameters) diff --git a/hed/tools/remodeling/operations/merge_consecutive_op.py b/hed/tools/remodeling/operations/merge_consecutive_op.py index 22ba34745..01a526a7a 100644 --- a/hed/tools/remodeling/operations/merge_consecutive_op.py +++ b/hed/tools/remodeling/operations/merge_consecutive_op.py @@ -33,18 +33,16 @@ def __init__(self, parameters): Parameters: parameters (dict): Actual values of the parameters for the operation. - Raises: + :raises KeyError: + - If a required parameter is missing. + - If an unexpected parameter is provided. - KeyError - - If a required parameter is missing. - - If an unexpected parameter is provided. + :raises TypeError: + - If a parameter has the wrong type. - TypeError - - If a parameter has the wrong type. - - ValueError - - If the specification is missing a valid operation. - - If one of the match column is the merge column. + :raises ValueError: + - If the specification is missing a valid operation. + - If one of the match column is the merge column. """ super().__init__(self.PARAMS, parameters) @@ -69,13 +67,11 @@ def do_op(self, dispatcher, df, name, sidecar=None): Returns: Dataframe: A new dataframe after processing. - Raises: - - ValueError - - If dataframe does not have the anchor column and ignore_missing is False. - - If a match column is missing and ignore_missing is false. - - If the durations were to be set and the dataframe did not have an onset column. - - If the durations were to be set and the dataframe did not have a duration column. + :raises ValueError: + - If dataframe does not have the anchor column and ignore_missing is False. + - If a match column is missing and ignore_missing is false. + - If the durations were to be set and the dataframe did not have an onset column. + - If the durations were to be set and the dataframe did not have a duration column. """ diff --git a/hed/tools/remodeling/operations/number_groups_op.py b/hed/tools/remodeling/operations/number_groups_op.py index bc9b96033..d3a5467db 100644 --- a/hed/tools/remodeling/operations/number_groups_op.py +++ b/hed/tools/remodeling/operations/number_groups_op.py @@ -95,7 +95,7 @@ def do_op(self, dispatcher, df, name, sidecar=None): df_new = df.copy() # # create number column # df_new[self.number_column_name] = np.nan - # + # # # find group indices # indices = tuple_to_range( # get_indices(df, self.source_column, self.start['values'], self.stop['values']), diff --git a/hed/tools/remodeling/operations/remap_columns_op.py b/hed/tools/remodeling/operations/remap_columns_op.py index 3f437ff97..480df8220 100644 --- a/hed/tools/remodeling/operations/remap_columns_op.py +++ b/hed/tools/remodeling/operations/remap_columns_op.py @@ -44,20 +44,19 @@ def __init__(self, parameters): Parameters: parameters (dict): Parameter values for required and optional parameters. - Raises: - KeyError - - If a required parameter is missing. - - If an unexpected parameter is provided. + :raises KeyError: + - If a required parameter is missing. + - If an unexpected parameter is provided. - TypeError - - If a parameter has the wrong type. + :raises TypeError: + - If a parameter has the wrong type. - ValueError - - If an integer column is not a key column. - - If a column designated as an integer source does not have valid integers. - - If no source columns are specified. - - If no destination columns are specified. - - If a map_list entry has the wrong number of items (source columns + destination columns). + :raises ValueError: + - If an integer column is not a key column. + - If a column designated as an integer source does not have valid integers. + - If no source columns are specified. + - If no destination columns are specified. + - If a map_list entry has the wrong number of items (source columns + destination columns). """ super().__init__(self.PARAMS, parameters) @@ -106,9 +105,8 @@ def do_op(self, dispatcher, df, name, sidecar=None): Returns: Dataframe: A new dataframe after processing. - Raises: - ValueError - - If ignore_missing is false and source values from the data are not in the map. + :raises ValueError: + - If ignore_missing is false and source values from the data are not in the map. """ df[self.source_columns] = df[self.source_columns].replace(np.NaN, 'n/a') diff --git a/hed/tools/remodeling/operations/remove_columns_op.py b/hed/tools/remodeling/operations/remove_columns_op.py index dd5ee0e2f..0a941ca5d 100644 --- a/hed/tools/remodeling/operations/remove_columns_op.py +++ b/hed/tools/remodeling/operations/remove_columns_op.py @@ -26,13 +26,12 @@ def __init__(self, parameters): Parameters: parameters (dict): Dictionary with the parameter values for required and optional parameters - Raises: - KeyError - - If a required parameter is missing. - - If an unexpected parameter is provided. + :raises KeyError: + - If a required parameter is missing. + - If an unexpected parameter is provided. - TypeError - - If a parameter has the wrong type. + :raises TypeError: + - If a parameter has the wrong type. """ super().__init__(self.PARAMS, parameters) @@ -55,9 +54,8 @@ def do_op(self, dispatcher, df, name, sidecar=None): Returns: Dataframe: A new dataframe after processing. - Raises: - KeyError - - If ignore_missing is False and a column not in the data is to be removed. + :raises KeyError: + - If ignore_missing is False and a column not in the data is to be removed. """ diff --git a/hed/tools/remodeling/operations/remove_rows_op.py b/hed/tools/remodeling/operations/remove_rows_op.py index 5f61d18ff..2e684d2dd 100644 --- a/hed/tools/remodeling/operations/remove_rows_op.py +++ b/hed/tools/remodeling/operations/remove_rows_op.py @@ -27,13 +27,12 @@ def __init__(self, parameters): Parameters: parameters (dict): Dictionary with the parameter values for required and optional parameters. - Raises: - KeyError - - If a required parameter is missing. - - If an unexpected parameter is provided. + :raises KeyError: + - If a required parameter is missing. + - If an unexpected parameter is provided. - TypeError - - If a parameter has the wrong type. + :raises TypeError: + - If a parameter has the wrong type. """ super().__init__(self.PARAMS, parameters) diff --git a/hed/tools/remodeling/operations/rename_columns_op.py b/hed/tools/remodeling/operations/rename_columns_op.py index c9a128b2e..adc283c20 100644 --- a/hed/tools/remodeling/operations/rename_columns_op.py +++ b/hed/tools/remodeling/operations/rename_columns_op.py @@ -27,13 +27,12 @@ def __init__(self, parameters): Parameters: parameters (dict): Dictionary with the parameter values for required and optional parameters - Raises: - KeyError - - If a required parameter is missing. - - If an unexpected parameter is provided. + :raises KeyError: + - If a required parameter is missing. + - If an unexpected parameter is provided. - TypeError - - If a parameter has the wrong type. + :raises TypeError: + - If a parameter has the wrong type. """ super().__init__(self.PARAMS, parameters) @@ -55,9 +54,8 @@ def do_op(self, dispatcher, df, name, sidecar=None): Returns: Dataframe: A new dataframe after processing. - Raises: - KeyError - - When ignore_missing is false and column_mapping has columns not in the data. + :raises KeyError: + - When ignore_missing is false and column_mapping has columns not in the data. """ diff --git a/hed/tools/remodeling/operations/reorder_columns_op.py b/hed/tools/remodeling/operations/reorder_columns_op.py index 32d9cb227..6ae71b179 100644 --- a/hed/tools/remodeling/operations/reorder_columns_op.py +++ b/hed/tools/remodeling/operations/reorder_columns_op.py @@ -28,13 +28,12 @@ def __init__(self, parameters): Parameters: parameters (dict): Dictionary with the parameter values for required and optional parameters. - Raises: - KeyError - - If a required parameter is missing. - - If an unexpected parameter is provided. + :raises KeyError: + - If a required parameter is missing. + - If an unexpected parameter is provided. - TypeError - If a parameter has the wrong type. + :raises TypeError: + - If a parameter has the wrong type. """ super().__init__(self.PARAMS, parameters) @@ -54,9 +53,8 @@ def do_op(self, dispatcher, df, name, sidecar=None): Returns: Dataframe: A new dataframe after processing. - Raises: - ValueError - - When ignore_missing is false and column_order has columns not in the data. + :raises ValueError: + - When ignore_missing is false and column_order has columns not in the data. """ diff --git a/hed/tools/remodeling/operations/split_rows_op.py b/hed/tools/remodeling/operations/split_rows_op.py index 3323af10e..e96e8b490 100644 --- a/hed/tools/remodeling/operations/split_rows_op.py +++ b/hed/tools/remodeling/operations/split_rows_op.py @@ -31,13 +31,12 @@ def __init__(self, parameters): Parameters: parameters (dict): Dictionary with the parameter values for required and optional parameters. - Raises: - KeyError - - If a required parameter is missing. - - If an unexpected parameter is provided. + :raises KeyError: + - If a required parameter is missing. + - If an unexpected parameter is provided. - TypeError - - If a parameter has the wrong type. + :raises TypeError: + - If a parameter has the wrong type. """ super().__init__(self.PARAMS, parameters) @@ -57,9 +56,8 @@ def do_op(self, dispatcher, df, name, sidecar=None): Returns: Dataframe: A new dataframe after processing. - Raises: - TypeError - -If bad onset or duration. + :raises TypeError: + -If bad onset or duration. """ @@ -121,8 +119,8 @@ def _create_onsets(df, onset_source): Returns: list: list of same length as df with the onsets. - Raises: - HedFileError: raised if one of the onset specifiers is invalid. + :raises HedFileError: + - If one of the onset specifiers is invalid. """ diff --git a/hed/tools/remodeling/operations/summarize_column_names_op.py b/hed/tools/remodeling/operations/summarize_column_names_op.py index da3be4e52..d185d08b2 100644 --- a/hed/tools/remodeling/operations/summarize_column_names_op.py +++ b/hed/tools/remodeling/operations/summarize_column_names_op.py @@ -35,13 +35,12 @@ def __init__(self, parameters): Parameters: parameters (dict): Dictionary with the parameter values for required and optional parameters. - Raises: - KeyError - - If a required parameter is missing. - - If an unexpected parameter is provided. + :raises KeyError: + - If a required parameter is missing. + - If an unexpected parameter is provided. - TypeError - - If a parameter has the wrong type. + :raises TypeError: + - If a parameter has the wrong type. """ super().__init__(self.PARAMS, parameters) diff --git a/hed/tools/remodeling/operations/summarize_column_values_op.py b/hed/tools/remodeling/operations/summarize_column_values_op.py index 64d67445f..539bfe2bd 100644 --- a/hed/tools/remodeling/operations/summarize_column_values_op.py +++ b/hed/tools/remodeling/operations/summarize_column_values_op.py @@ -46,14 +46,12 @@ def __init__(self, parameters): Parameters: parameters (dict): Dictionary with the parameter values for required and optional parameters. - Raises: + :raises KeyError: + - If a required parameter is missing. + - If an unexpected parameter is provided. - KeyError - - If a required parameter is missing. - - If an unexpected parameter is provided. - - TypeError - - If a parameter has the wrong type. + :raises TypeError: + - If a parameter has the wrong type. """ diff --git a/hed/tools/remodeling/operations/summarize_definitions_op.py b/hed/tools/remodeling/operations/summarize_definitions_op.py index aa880307f..bc988c5d3 100644 --- a/hed/tools/remodeling/operations/summarize_definitions_op.py +++ b/hed/tools/remodeling/operations/summarize_definitions_op.py @@ -36,14 +36,12 @@ def __init__(self, parameters): Parameters: parameters (dict): Dictionary with the parameter values for required and optional parameters. - Raises: + :raises KeyError: + - If a required parameter is missing. + - If an unexpected parameter is provided. - KeyError - - If a required parameter is missing. - - If an unexpected parameter is provided. - - TypeError - - If a parameter has the wrong type. + :raises TypeError: + - If a parameter has the wrong type. """ @@ -87,7 +85,7 @@ def update_summary(self, new_info): new_info (dict): A dictionary with the parameters needed to update a summary. Notes: - - The summary needs a "name" str, a "schema" and a "Sidecar". + - The summary needs a "name" str, a "schema" and a "Sidecar". """ data_input = TabularInput(new_info['df'], sidecar=new_info['sidecar'], name=new_info['name']) diff --git a/hed/tools/remodeling/operations/summarize_hed_tags_op.py b/hed/tools/remodeling/operations/summarize_hed_tags_op.py index 5d58b78fd..2c24de8ef 100644 --- a/hed/tools/remodeling/operations/summarize_hed_tags_op.py +++ b/hed/tools/remodeling/operations/summarize_hed_tags_op.py @@ -47,13 +47,12 @@ def __init__(self, parameters): Parameters: parameters (dict): Dictionary with the parameter values for required and optional parameters. - Raises: - KeyError - - If a required parameter is missing. - - If an unexpected parameter is provided. + :raises KeyError: + - If a required parameter is missing. + - If an unexpected parameter is provided. - TypeError - - If a parameter has the wrong type. + :raises TypeError: + - If a parameter has the wrong type. """ super().__init__(self.PARAMS, parameters) @@ -110,7 +109,7 @@ def update_summary(self, new_info): if sidecar and not isinstance(sidecar, Sidecar): sidecar = Sidecar(sidecar) input_data = TabularInput(new_info['df'], sidecar=sidecar, name=new_info['name']) - hed_strings, definitions = get_assembled(input_data, sidecar, new_info['schema'], + hed_strings, definitions = get_assembled(input_data, sidecar, new_info['schema'], extra_def_dicts=None, join_columns=True, shrink_defs=False, expand_defs=True) # definitions = input_data.get_definitions().gathered_defs diff --git a/hed/tools/remodeling/operations/summarize_hed_type_op.py b/hed/tools/remodeling/operations/summarize_hed_type_op.py index 1a8c51211..6a37b0578 100644 --- a/hed/tools/remodeling/operations/summarize_hed_type_op.py +++ b/hed/tools/remodeling/operations/summarize_hed_type_op.py @@ -43,13 +43,12 @@ def __init__(self, parameters): Parameters: parameters (dict): Dictionary with the parameter values for required and optional parameters. - Raises: - KeyError - - If a required parameter is missing. - - If an unexpected parameter is provided. + :raises KeyError: + - If a required parameter is missing. + - If an unexpected parameter is provided. - TypeError - - If a parameter has the wrong type. + :raises TypeError: + - If a parameter has the wrong type. """ super().__init__(self.PARAMS, parameters) diff --git a/hed/tools/remodeling/operations/summarize_hed_validation_op.py b/hed/tools/remodeling/operations/summarize_hed_validation_op.py index 0633c5b57..29812273d 100644 --- a/hed/tools/remodeling/operations/summarize_hed_validation_op.py +++ b/hed/tools/remodeling/operations/summarize_hed_validation_op.py @@ -40,13 +40,12 @@ def __init__(self, parameters): Parameters: parameters (dict): Dictionary with the parameter values for required and optional parameters. - Raises: - KeyError - - If a required parameter is missing. - - If an unexpected parameter is provided. + :raises KeyError: + - If a required parameter is missing. + - If an unexpected parameter is provided. - TypeError - - If a parameter has the wrong type. + :raises TypeError: + - If a parameter has the wrong type. """ super().__init__(self.PARAMS, parameters) @@ -123,7 +122,7 @@ def update_summary(self, new_info): new_info (dict): A dictionary with the parameters needed to update a summary. Notes: - - The summary needs a "name" str, a schema, a "df", and a "Sidecar". + - The summary needs a "name" str, a schema, a "df", and a "Sidecar". """ results = self.get_empty_results() diff --git a/hed/tools/remodeling/operations/summarize_sidecar_from_events_op.py b/hed/tools/remodeling/operations/summarize_sidecar_from_events_op.py index b191f0525..f206e2f5f 100644 --- a/hed/tools/remodeling/operations/summarize_sidecar_from_events_op.py +++ b/hed/tools/remodeling/operations/summarize_sidecar_from_events_op.py @@ -40,13 +40,12 @@ def __init__(self, parameters): Parameters: parameters (dict): Dictionary with the parameter values for required and optional parameters. - Raises: - KeyError - - If a required parameter is missing. - - If an unexpected parameter is provided. + :raises KeyError: + - If a required parameter is missing. + - If an unexpected parameter is provided. - TypeError - - If a parameter has the wrong type. + :raises TypeError: + - If a parameter has the wrong type. """ diff --git a/hed/tools/util/data_util.py b/hed/tools/util/data_util.py index 5e4809d1a..ece1ea61f 100644 --- a/hed/tools/util/data_util.py +++ b/hed/tools/util/data_util.py @@ -131,8 +131,8 @@ def get_new_dataframe(data): DataFrame: A dataframe containing the contents of the tsv file or if data was a DataFrame to start with, a new copy of the DataFrame. - Raises: - HedFileError: If a filename is given and it cannot be read into a Dataframe. + :raises HedFileError: + - If a filename is given and it cannot be read into a Dataframe. """ @@ -155,8 +155,8 @@ def get_row_hash(row, key_list): Returns: str: Hash key constructed from the entries of row in the columns specified by key_list. - Raises: - HedFileError: If row doesn't have all of the columns in key_list HedFileError is raised. + :raises HedFileError: + - If row doesn't have all of the columns in key_list HedFileError is raised. """ columns_present, columns_missing = separate_values(list(row.index.values), key_list) @@ -177,8 +177,8 @@ def get_value_dict(tsv_path, key_col='file_basename', value_col='sampling_rate') Returns: dict: Dictionary with key_col values as the keys and the corresponding value_col values as the values. - Raises: - HedFileError: When tsv_path does not correspond to a file that can be read into a DataFrame. + :raises HedFileError: + - When tsv_path does not correspond to a file that can be read into a DataFrame. """ @@ -252,9 +252,10 @@ def reorder_columns(data, col_order, skip_missing=True): Returns: DataFrame: A new reordered dataframe. - Raises: - HedFileError: If col_order contains columns not in data and skip_missing is False or if - data corresponds to a filename from which a dataframe cannot be created. + :raises HedFileError: + - If col_order contains columns not in data and skip_missing is False. + - If data corresponds to a filename from which a dataframe cannot be created. + """ df = get_new_dataframe(data) present_cols, missing_cols = separate_values(df.columns.values.tolist(), col_order) diff --git a/hed/tools/util/io_util.py b/hed/tools/util/io_util.py index 97489ce26..9a27be4ef 100644 --- a/hed/tools/util/io_util.py +++ b/hed/tools/util/io_util.py @@ -265,10 +265,10 @@ def parse_bids_filename(file_path): str: File extension (including the .). dict: Dictionary with key-value pair being (entity type, entity value). - Raises: - HedFileError when filename does not conform to name-value_suffix format. + :raises HedFileError: + - If filename does not conform to name-value_suffix format. - Notes: + Notes: into BIDS suffix, extension, and a dictionary of entity name-value pairs. """ From 94d5b67a31256faac2cc2d11af2e8163b43418f6 Mon Sep 17 00:00:00 2001 From: Kay Robbins <1189050+VisLab@users.noreply.github.com> Date: Tue, 13 Jun 2023 11:09:10 -0500 Subject: [PATCH 5/5] Minor tweaks to docs --- docs/source/api2.rst | 2 +- hed/models/column_mapper.py | 20 ++++++++++++------- hed/models/df_util.py | 10 +++++----- hed/models/hed_tag.py | 4 ++-- hed/models/spreadsheet_input.py | 14 ++++++++----- hed/schema/hed_schema.py | 27 ++++++++++++++------------ hed/schema/schema_io/schema_util.py | 13 ++++++------- hed/tools/remodeling/backup_manager.py | 4 ++-- hed/tools/remodeling/dispatcher.py | 14 ++++++------- hed/tools/util/data_util.py | 4 ++-- hed/tools/util/io_util.py | 6 +++--- 11 files changed, 65 insertions(+), 53 deletions(-) diff --git a/docs/source/api2.rst b/docs/source/api2.rst index 359eba4a2..02d3aeaed 100644 --- a/docs/source/api2.rst +++ b/docs/source/api2.rst @@ -1,5 +1,5 @@ HED API reference (Auto style) -======================== +============================== .. currentmodule:: hed diff --git a/hed/models/column_mapper.py b/hed/models/column_mapper.py index 3e82d8c5a..6b5d651cf 100644 --- a/hed/models/column_mapper.py +++ b/hed/models/column_mapper.py @@ -26,19 +26,23 @@ 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. - May be deprecated/renamed. These are no longer prefixes, but rather converted to value columns. - eg. {"key": "Description", 1: "Label/"} will turn into value columns as - {"key": "Description/#", 1: "Label/#"} - Note: 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. + 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 the sidecar. Notes: - - All column numbers are 0 based. + - All column numbers are 0 based. + - The column_prefix_dictionary may be deprecated/renamed in the future. + - These are no longer prefixes, but rather converted to value columns: + {"key": "Description", 1: "Label/"} will turn into value columns as + {"key": "Description/#", 1: "Label/#"} + 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. + """ + # Maps column number to column_entry. This is what's actually used by most code. self._final_column_map = {} self._no_mapping_info = True @@ -384,7 +388,9 @@ def get_def_dict(self, hed_schema=None, extra_def_dicts=None): def get_column_mapping_issues(self): """ Get all the issues with finalizing column mapping(duplicate columns, missing required, etc) - Note: this is deprecated and now a wrapper for "check_for_mapping_issues()" + Notes: + - This is deprecated and now a wrapper for "check_for_mapping_issues()" + Returns: list: A list dictionaries of all issues found from mapping column names to numbers. diff --git a/hed/models/df_util.py b/hed/models/df_util.py index 6cd4943df..2509a059a 100644 --- a/hed/models/df_util.py +++ b/hed/models/df_util.py @@ -56,14 +56,14 @@ def get_assembled(tabular_file, sidecar, hed_schema, extra_def_dicts=None, join_ def convert_to_form(df, hed_schema, tag_form, columns=None): - """ Convert all tags in underlying dataframe to the specified form. + """ Convert all tags in underlying dataframe to the specified form (in place). - Converts in place Parameters: df (pd.Dataframe): The dataframe to modify hed_schema (HedSchema): The schema to use to convert tags. tag_form(str): HedTag property to convert tags to. - columns (list): The columns to modify on the dataframe + columns (list): The columns to modify on the dataframe. + """ if isinstance(df, pd.Series): df = df.apply(partial(_convert_to_form, hed_schema=hed_schema, tag_form=tag_form)) @@ -78,13 +78,13 @@ def convert_to_form(df, hed_schema, tag_form, columns=None): def shrink_defs(df, hed_schema, columns=None): - """ Shrinks any def-expand tags found in the specified columns in the dataframe. + """ Shrink (in place) any def-expand tags found in the specified columns in the dataframe. - Converts in place Parameters: df (pd.Dataframe or pd.Series): The dataframe or series to modify hed_schema (HedSchema or None): The schema to use to identify defs. columns (list or None): The columns to modify on the dataframe. + """ if isinstance(df, pd.Series): mask = df.str.contains('Def-expand/', case=False) diff --git a/hed/models/hed_tag.py b/hed/models/hed_tag.py index 44f1612dc..2c17d368a 100644 --- a/hed/models/hed_tag.py +++ b/hed/models/hed_tag.py @@ -135,6 +135,7 @@ def short_base_tag(self, new_tag_val): Note: - Generally this is used to swap def to def-expand. + """ if self._schema_entry: tag_entry = None @@ -156,8 +157,7 @@ def org_base_tag(self): Notes: - 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. - + e.g. a column where "Label/" is prepended, thus the column value has zero base portion. - Only valid after calling convert_to_canonical_forms. """ diff --git a/hed/models/spreadsheet_input.py b/hed/models/spreadsheet_input.py index 1c9b98520..c3a059bdc 100644 --- a/hed/models/spreadsheet_input.py +++ b/hed/models/spreadsheet_input.py @@ -21,11 +21,15 @@ def __init__(self, file=None, file_type=None, worksheet_name=None, tag_columns=N first line of the file if the spreadsheet as column names. 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. - May be deprecated/renamed. These are no longer prefixes, but rather converted to value columns. - eg. {"key": "Description", 1: "Label/"} will turn into value columns as - {"key": "Description/#", 1: "Label/#"} - Note: 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. + + Notes: + - column_prefix_dictionary may be deprecated/renamed. These are no longer prefixes, + but rather converted to value columns. + eg. {"key": "Description", 1: "Label/"} will turn into value columns as + {"key": "Description/#", 1: "Label/#"} + 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. + """ if tag_columns is None: tag_columns = [1] diff --git a/hed/schema/hed_schema.py b/hed/schema/hed_schema.py index 8d5e363c8..f27c97cb1 100644 --- a/hed/schema/hed_schema.py +++ b/hed/schema/hed_schema.py @@ -12,6 +12,7 @@ from hed.errors import ErrorHandler from hed.errors.error_types import ValidationErrors + class HedSchema: """ A HED schema suitable for processing. """ @@ -93,7 +94,9 @@ def get_save_header_attributes(self, save_merged=False): """ sort_to_start = "!!!!!!!!!!!!!!" - header_attributes = dict(sorted(self.header_attributes.items(), key=lambda x: sort_to_start if x[0] == constants.VERSION_ATTRIBUTE else x[0], reverse=False)) + header_attributes = dict(sorted(self.header_attributes.items(), + key=lambda x: sort_to_start if x[0] == constants.VERSION_ATTRIBUTE else x[0], + reverse=False)) if save_merged: header_attributes.pop(constants.UNMERGED_ATTRIBUTE, None) else: @@ -101,7 +104,6 @@ def get_save_header_attributes(self, save_merged=False): header_attributes.pop(constants.UNMERGED_ATTRIBUTE, None) header_attributes[constants.UNMERGED_ATTRIBUTE] = "True" - return header_attributes def schema_for_namespace(self, namespace): @@ -139,9 +141,10 @@ def valid_prefixes(self): def get_as_mediawiki_string(self, save_merged=False): """ Return the schema to a mediawiki string. - save_merged: bool - If true, this will save the schema as a merged schema if it is a "withStandard" schema. - If it is not a "withStandard" schema, this setting has no effect. + Parameters: + save_merged (bool): If true, this will save the schema as a merged schema if it is a "withStandard" schema. + If it is not a "withStandard" schema, this setting has no effect. + Returns: str: The schema as a string in mediawiki format. @@ -153,7 +156,8 @@ def get_as_mediawiki_string(self, save_merged=False): def get_as_xml_string(self, save_merged=True): """ Return the schema to an XML string. - save_merged: bool + Parameters: + save_merged (bool): If true, this will save the schema as a merged schema if it is a "withStandard" schema. If it is not a "withStandard" schema, this setting has no effect. Returns: @@ -250,7 +254,7 @@ def find_duplicate_tags(self): Notes: - The returned dictionary has the short-form tags as keys and lists - of long tags sharing the short form as the values. + of long tags sharing the short form as the values. """ return self.all_tags.duplicate_names @@ -651,9 +655,8 @@ def get_unknown_attributes(self): dict: The keys are attribute names and the values are lists of tags with this attribute. Notes: - This includes attributes found in the wrong section for example - unitClass attribute found on a Tag. - The return tag list is in long form. + - This includes attributes found in the wrong section for example unitClass attribute found on a Tag. + - The return tag list is in long form. """ unknown_attributes = {} @@ -762,7 +765,7 @@ def _get_attributes_for_section(self, key_class): if key_class == HedSectionKey.AllTags: return self.get_tag_attribute_names() elif key_class == HedSectionKey.Attributes: - prop_added_dict = {key:value for key, value in self._sections[HedSectionKey.Properties].items()} + prop_added_dict = {key: value for key, value in self._sections[HedSectionKey.Properties].items()} self._add_element_property_attributes(prop_added_dict) return prop_added_dict elif key_class == HedSectionKey.Properties: @@ -797,4 +800,4 @@ def _add_tag_to_dict(self, long_tag_name, new_entry, key_class): def _create_tag_entry(self, long_tag_name, key_class): section = self._sections[key_class] - return section._create_tag_entry(long_tag_name) \ No newline at end of file + return section._create_tag_entry(long_tag_name) diff --git a/hed/schema/schema_io/schema_util.py b/hed/schema/schema_io/schema_util.py index 0469f5692..2135e0aa1 100644 --- a/hed/schema/schema_io/schema_util.py +++ b/hed/schema/schema_io/schema_util.py @@ -24,16 +24,15 @@ def get_api_key(): def make_url_request(resource_url, try_authenticate=True): - """ - Make sa request and adds the above Github access credentials - Args: - resource_url: str - The url to retrieve - try_authenticate: bool - If true add the above credentials + """ Make a request and adds the above Github access credentials. + + Parameters: + resource_url (str): The url to retrieve. + try_authenticate (bool): If true add the above credentials. Returns: url_request + """ request = urllib.request.Request(resource_url) if try_authenticate and get_api_key(): diff --git a/hed/tools/remodeling/backup_manager.py b/hed/tools/remodeling/backup_manager.py index 3402fae28..e06922a32 100644 --- a/hed/tools/remodeling/backup_manager.py +++ b/hed/tools/remodeling/backup_manager.py @@ -222,12 +222,12 @@ def _check_backup_consistency(self, backup_name): def get_task(task_names, file_path): """ Return the task if the file name contains a task_xxx where xxx is in task_names. - Args: + Parameters: task_names (list): List of task names (without the task_ prefix). file_path (str): Path of the filename to be tested. Returns: - str the task name or '' if there is no task_xxx or xxx is not in task_names. + str: the task name or '' if there is no task_xxx or xxx is not in task_names. """ diff --git a/hed/tools/remodeling/dispatcher.py b/hed/tools/remodeling/dispatcher.py index ad033a5b5..48f862937 100644 --- a/hed/tools/remodeling/dispatcher.py +++ b/hed/tools/remodeling/dispatcher.py @@ -92,13 +92,13 @@ def get_data_file(self, file_designator): :raises HedFileError: - If a valid file cannot be found. - Notes: - - If a string is passed and there is a backup manager, - the string must correspond to the full path of the file in the original dataset. - In this case, the corresponding backup file is read and returned. - - If a string is passed and there is no backup manager, - the data file corresponding to the file_designator is read and returned. - - If a Pandas DataFrame is passed, a copy is returned. + Notes: + - If a string is passed and there is a backup manager, + the string must correspond to the full path of the file in the original dataset. + In this case, the corresponding backup file is read and returned. + - If a string is passed and there is no backup manager, + the data file corresponding to the file_designator is read and returned. + - If a Pandas DataFrame is passed, a copy is returned. """ if isinstance(file_designator, pd.DataFrame): diff --git a/hed/tools/util/data_util.py b/hed/tools/util/data_util.py index ece1ea61f..a6866909c 100644 --- a/hed/tools/util/data_util.py +++ b/hed/tools/util/data_util.py @@ -277,9 +277,9 @@ def separate_values(values, target_values): list: Target values present in values. list: Target values missing from values. - Notes: + Notes: - The function computes the set difference of target_cols and base_cols and returns a list - of columns of target_cols that are in base_cols and a list of those missing. + of columns of target_cols that are in base_cols and a list of those missing. """ diff --git a/hed/tools/util/io_util.py b/hed/tools/util/io_util.py index 9a27be4ef..a120c9040 100644 --- a/hed/tools/util/io_util.py +++ b/hed/tools/util/io_util.py @@ -266,10 +266,10 @@ def parse_bids_filename(file_path): dict: Dictionary with key-value pair being (entity type, entity value). :raises HedFileError: - - If filename does not conform to name-value_suffix format. + - If filename does not conform to name-value_suffix format. - Notes: - into BIDS suffix, extension, and a dictionary of entity name-value pairs. + Notes: + - splits into BIDS suffix, extension, and a dictionary of entity name-value pairs. """