From e9398ac1e940a7784a174e59073b1e82dd558514 Mon Sep 17 00:00:00 2001 From: Kay Robbins <1189050+VisLab@users.noreply.github.com> Date: Mon, 3 Jul 2023 17:12:08 -0500 Subject: [PATCH 1/2] Updated License file --- CHANGELOG.md | 7 +++++++ LICENSE | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d02b3de6..a3931b8c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +Release 0.3.1 July 3, 2023 +- Pinned the version of the pydantic and inflect libraries due to inflict. +- Reorganized JSON output of remodeling summaries so that all of consistent form. +- Fixed summarize_hed_tags_op so that tags were correctly categorized for output. +- Minor refactoring to reduce code complexity. + + Release 0.3.0 June 20, 2023 - Introduction of partnered schema. - Improved error handling for schema validation. diff --git a/LICENSE b/LICENSE index 2be171efb..2e7808f43 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -MIT License +The MIT License (MIT) Copyright (c) 2020+ HED Standard Working Group From de598d14fa33262da7955df455b52764c0e200ab Mon Sep 17 00:00:00 2001 From: Kay Robbins <1189050+VisLab@users.noreply.github.com> Date: Tue, 4 Jul 2023 11:06:57 -0500 Subject: [PATCH 2/2] Updated exception handling in BaseInput and Sidecar for Invalid file formats --- CHANGELOG.md | 1 + hed/errors/exceptions.py | 2 +- hed/models/base_input.py | 8 +++++--- hed/models/sidecar.py | 6 ++---- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3931b8c0..316d45dfe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Release 0.3.1 July 3, 2023 - Reorganized JSON output of remodeling summaries so that all of consistent form. - Fixed summarize_hed_tags_op so that tags were correctly categorized for output. - Minor refactoring to reduce code complexity. +- BaseInput and Sidecar now raise HedFileError if input could not be read. Release 0.3.0 June 20, 2023 diff --git a/hed/errors/exceptions.py b/hed/errors/exceptions.py index 9f8ddbeb7..a1def1caf 100644 --- a/hed/errors/exceptions.py +++ b/hed/errors/exceptions.py @@ -11,7 +11,7 @@ class HedExceptions: INVALID_EXTENSION = 'invalidExtension' INVALID_DATAFRAME = 'INVALID_DATAFRAME' - + INVALID_FILE_FORMAT = 'INVALID_FILE_FORMAT' # These are actual schema issues, not that the file cannot be found or parsed SCHEMA_HEADER_MISSING = 'HED_SCHEMA_HEADER_INVALID' HED_SCHEMA_HEADER_INVALID = 'HED_SCHEMA_HEADER_INVALID' diff --git a/hed/models/base_input.py b/hed/models/base_input.py index 5a78729e8..852d7bd6f 100644 --- a/hed/models/base_input.py +++ b/hed/models/base_input.py @@ -45,6 +45,8 @@ def __init__(self, file, file_type=None, worksheet_name=None, has_column_names=T - A duplicate or empty column name appears - Cannot open the indicated file - The specified worksheet name does not exist + - If the sidecar file or tabular file had invalid format and could not be read. + """ if mapper is None: mapper = ColumnMapper() @@ -77,7 +79,7 @@ def __init__(self, file, file_type=None, worksheet_name=None, has_column_names=T self._dataframe = pandas.read_csv(file, delimiter='\t', header=pandas_header, dtype=str, keep_default_na=True, na_values=None) except Exception as e: - raise HedFileError(HedExceptions.GENERIC_ERROR, str(e), self.name) from e + raise HedFileError(HedExceptions.INVALID_FILE_FORMAT, str(e), self.name) from e # Convert nan values to a known value self._dataframe = self._dataframe.fillna("n/a") elif input_type in self.EXCEL_EXTENSION: @@ -96,7 +98,7 @@ def __init__(self, file, file_type=None, worksheet_name=None, has_column_names=T # todo: Can we get rid of this behavior now that we're using pandas? column_issues = ColumnMapper.check_for_blank_names(self.columns, allow_blank_names=allow_blank_names) if column_issues: - raise HedFileError(HedExceptions.BAD_COLUMN_NAMES, "Duplicate or blank columns found. See issues.", + raise HedFileError(HedExceptions.BAD_COLUMN_NAMES, "Duplicate or blank columns found. See issues.", self.name, issues=column_issues) self.reset_mapper(mapper) @@ -287,7 +289,7 @@ 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 diff --git a/hed/models/sidecar.py b/hed/models/sidecar.py index 867ba2e20..d3038fff6 100644 --- a/hed/models/sidecar.py +++ b/hed/models/sidecar.py @@ -127,15 +127,13 @@ def load_sidecar_file(self, file): if not file: return {} elif isinstance(file, str): + if not self.name: + self.name = file try: with open(file, "r") as fp: - if not self.name: - self.name = file return self._load_json_file(fp) except OSError as e: raise HedFileError(HedExceptions.FILE_NOT_FOUND, e.strerror, file) from e - except TypeError as e: - raise HedFileError(HedExceptions.FILE_NOT_FOUND, str(e), file) from e else: return self._load_json_file(file)