Skip to content

Commit b9cfeaf

Browse files
committed
Changed the ruff options -- resulted in reformatting
1 parent 95ec60d commit b9cfeaf

114 files changed

Lines changed: 1171 additions & 366 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/validate_bids_dataset_with_libraries.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@
4646
"print(\"\\nNow validating with schema URLs.\")\n",
4747
"base_version = \"8.3.0\"\n",
4848
"library1_url = (\n",
49-
" \"https://raw.githubusercontent.com/hed-standard/hed-schemas/main/\" + \"library_schemas/score/hedxml/HED_score_2.0.0.xml\"\n",
49+
" \"https://raw.githubusercontent.com/hed-standard/hed-schemas/main/\"\n",
50+
" + \"library_schemas/score/hedxml/HED_score_2.0.0.xml\"\n",
5051
")\n",
5152
"library2_url = (\n",
52-
" \"https://raw.githubusercontent.com/hed-standard/hed-schemas/main/\" + \"library_schemas/testlib/hedxml/HED_testlib_1.0.2.xml\"\n",
53+
" \"https://raw.githubusercontent.com/hed-standard/hed-schemas/main/\"\n",
54+
" + \"library_schemas/testlib/hedxml/HED_testlib_1.0.2.xml\"\n",
5355
")\n",
5456
"schema_list = [load_schema(library1_url, schema_namespace=\"\"), load_schema(library2_url, schema_namespace=\"test\")]\n",
5557
"bids.schema = HedSchemaGroup(schema_list)\n",

hed/errors/error_messages.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ def val_error_invalid_extension(tag):
167167
return f'Invalid extension on tag - "{tag}"'
168168

169169

170-
@hed_tag_error(ValidationErrors.INVALID_PARENT_NODE, has_sub_tag=True, actual_code=ValidationErrors.TAG_EXTENSION_INVALID)
170+
@hed_tag_error(
171+
ValidationErrors.INVALID_PARENT_NODE, has_sub_tag=True, actual_code=ValidationErrors.TAG_EXTENSION_INVALID
172+
)
171173
def val_error_invalid_parent(tag, problem_tag, expected_parent_tag):
172174
return f"In '{tag}', '{problem_tag}' appears as '{str(expected_parent_tag)}' and cannot be used as an extension."
173175

@@ -192,7 +194,9 @@ def val_error_missing_column(column_name, column_type):
192194

193195
@hed_error(ValidationErrors.HED_UNKNOWN_COLUMN, default_severity=ErrorSeverity.WARNING)
194196
def val_error_extra_column(column_name):
195-
return f"Column named '{column_name}' found in file, but not specified as a tag column " + "or identified in sidecars."
197+
return (
198+
f"Column named '{column_name}' found in file, but not specified as a tag column " + "or identified in sidecars."
199+
)
196200

197201

198202
@hed_error(ValidationErrors.SIDECAR_AND_OTHER_COLUMNS)
@@ -300,7 +304,8 @@ def val_error_tag_group_tag(tag):
300304
def val_error_top_level_tags(tag, multiple_tags):
301305
tags_as_string = [str(tag) for tag in multiple_tags]
302306
return (
303-
f"Multiple top level tags found in a single group. First one found: {str(tag)}. " + f"Remainder:{str(tags_as_string)}"
307+
f"Multiple top level tags found in a single group. First one found: {str(tag)}. "
308+
+ f"Remainder:{str(tags_as_string)}"
304309
)
305310

306311

@@ -359,9 +364,7 @@ def sidecar_na_used(column_name):
359364

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

366369

367370
@hed_error(DefinitionErrors.NO_DEFINITION_CONTENTS, actual_code=ValidationErrors.DEFINITION_INVALID)
@@ -527,7 +530,9 @@ def improper_event_groups(event_types, string, line):
527530

528531

529532
@hed_error(
530-
TagQualityErrors.MISSING_TASK_ROLE, default_severity=ErrorSeverity.WARNING, actual_code=TagQualityErrors.MISSING_TASK_ROLE
533+
TagQualityErrors.MISSING_TASK_ROLE,
534+
default_severity=ErrorSeverity.WARNING,
535+
actual_code=TagQualityErrors.MISSING_TASK_ROLE,
531536
)
532537
def missing_task_role(event_type, string, line):
533538
return f"The HED string '{string}' at line {line} with event {event_type} has no Task-event-role type tag."

hed/errors/error_reporter.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,10 @@ def create_doc_link(error_code):
626626
Returns:
627627
Union[str, None]: The URL if it's a valid code.
628628
"""
629-
if error_code in known_error_codes["hed_validation_errors"] or error_code in known_error_codes["schema_validation_errors"]:
629+
if (
630+
error_code in known_error_codes["hed_validation_errors"]
631+
or error_code in known_error_codes["schema_validation_errors"]
632+
):
630633
modified_error_code = error_code.replace("_", "-").lower()
631634
return f"https://www.hedtags.org/hed-specification/Appendix_B.html#{modified_error_code}"
632635
return None

hed/errors/schema_error_messages.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ def schema_error_SCHEMA_PRERELEASE_VERSION_USED(current_version, known_versions)
6363
)
6464
def schema_error_invalid_character_prologue(char_index, source_string, section_name):
6565
invalid_char = source_string[char_index]
66-
return f"'{section_name}' has invalid character '{invalid_char}' at " + f"position {char_index} of string: {source_string}"
66+
return (
67+
f"'{section_name}' has invalid character '{invalid_char}' at "
68+
+ f"position {char_index} of string: {source_string}"
69+
)
6770

6871

6972
@hed_error(
@@ -114,7 +117,9 @@ def schema_error_SCHEMA_CHILD_OF_DEPRECATED(deprecated_tag, non_deprecated_child
114117
return f"Deprecated tag '{deprecated_tag}' has a child that is not deprecated: '{non_deprecated_child}'."
115118

116119

117-
@hed_error(SchemaAttributeErrors.SCHEMA_ATTRIBUTE_VALUE_DEPRECATED, actual_code=SchemaAttributeErrors.SCHEMA_DEPRECATION_ERROR)
120+
@hed_error(
121+
SchemaAttributeErrors.SCHEMA_ATTRIBUTE_VALUE_DEPRECATED, actual_code=SchemaAttributeErrors.SCHEMA_DEPRECATION_ERROR
122+
)
118123
def schema_error_SCHEMA_ATTRIBUTE_VALUE_DEPRECATED(tag, deprecated_suggestion, attribute_name):
119124
return (
120125
f"Tag '{tag}' {attribute_name} uses '{deprecated_suggestion}' which has been deprecated "
@@ -131,7 +136,8 @@ def schema_error_GENERIC_ATTRIBUTE_VALUE_INVALID(tag, invalid_value, attribute_n
131136

132137

133138
@hed_error(
134-
SchemaAttributeErrors.SCHEMA_ATTRIBUTE_NUMERIC_INVALID, actual_code=SchemaAttributeErrors.SCHEMA_ATTRIBUTE_VALUE_INVALID
139+
SchemaAttributeErrors.SCHEMA_ATTRIBUTE_NUMERIC_INVALID,
140+
actual_code=SchemaAttributeErrors.SCHEMA_ATTRIBUTE_VALUE_INVALID,
135141
)
136142
def schema_error_SCHEMA_ATTRIBUTE_NUMERIC_INVALID(tag, invalid_value, attribute_name):
137143
return f"Element '{tag}' has an invalid {attribute_name}: '{invalid_value}'. Should be numeric."
@@ -145,7 +151,9 @@ def schema_error_SCHEMA_DEFAULT_UNITS_INVALID(tag, bad_unit, valid_units):
145151
return f"Tag '{tag}' has an invalid defaultUnit '{bad_unit}'. Valid units are: '{valid_units}'."
146152

147153

148-
@hed_error(SchemaAttributeErrors.SCHEMA_DEFAULT_UNITS_DEPRECATED, actual_code=SchemaAttributeErrors.SCHEMA_DEPRECATION_ERROR)
154+
@hed_error(
155+
SchemaAttributeErrors.SCHEMA_DEFAULT_UNITS_DEPRECATED, actual_code=SchemaAttributeErrors.SCHEMA_DEPRECATION_ERROR
156+
)
149157
def schema_error_SCHEMA_DEFAULT_UNITS_DEPRECATED(unit_class, bad_unit):
150158
return f"Unit class '{unit_class}' defaultUnit '{bad_unit}' is deprecated. Please find an alternative default."
151159

@@ -158,7 +166,9 @@ def schema_error_SCHEMA_CONVERSION_FACTOR_NOT_POSITIVE(tag, conversion_factor):
158166
return f"Tag '{tag}' has an invalid conversionFactor '{conversion_factor}'. Conversion factor must be positive."
159167

160168

161-
@hed_error(SchemaAttributeErrors.SCHEMA_HED_ID_INVALID, actual_code=SchemaAttributeErrors.SCHEMA_ATTRIBUTE_VALUE_INVALID)
169+
@hed_error(
170+
SchemaAttributeErrors.SCHEMA_HED_ID_INVALID, actual_code=SchemaAttributeErrors.SCHEMA_ATTRIBUTE_VALUE_INVALID
171+
)
162172
def schema_error_SCHEMA_HED_ID_INVALID(tag, new_id, old_id=None, valid_min=None, valid_max=None):
163173
if old_id:
164174
return (
@@ -171,7 +181,8 @@ def schema_error_SCHEMA_HED_ID_INVALID(tag, new_id, old_id=None, valid_min=None,
171181

172182

173183
@hed_error(
174-
SchemaAttributeErrors.SCHEMA_ALLOWED_CHARACTERS_INVALID, actual_code=SchemaAttributeErrors.SCHEMA_ATTRIBUTE_VALUE_INVALID
184+
SchemaAttributeErrors.SCHEMA_ALLOWED_CHARACTERS_INVALID,
185+
actual_code=SchemaAttributeErrors.SCHEMA_ATTRIBUTE_VALUE_INVALID,
175186
)
176187
def schema_error_SCHEMA_ALLOWED_CHARACTERS_INVALID(tag, invalid_character):
177188
from hed.schema.hed_schema_constants import character_types
@@ -183,7 +194,9 @@ def schema_error_SCHEMA_ALLOWED_CHARACTERS_INVALID(tag, invalid_character):
183194
)
184195

185196

186-
@hed_error(SchemaAttributeErrors.SCHEMA_IN_LIBRARY_INVALID, actual_code=SchemaAttributeErrors.SCHEMA_ATTRIBUTE_VALUE_INVALID)
197+
@hed_error(
198+
SchemaAttributeErrors.SCHEMA_IN_LIBRARY_INVALID, actual_code=SchemaAttributeErrors.SCHEMA_ATTRIBUTE_VALUE_INVALID
199+
)
187200
def schema_error_SCHEMA_IN_LIBRARY_INVALID(tag, bad_library):
188201
return f"Tag '{tag}' has an invalid inLibrary: '{bad_library}'. "
189202

@@ -198,9 +211,7 @@ def schema_error_SCHEMA_MISSING_EXTRA_VALUE(section_name, column_name, row_index
198211
default_severity=ErrorSeverity.WARNING,
199212
)
200213
def schema_error_annotation_prefix_missing(tag, annotation_value, prefix):
201-
return (
202-
f"Tag '{tag}' has annotation '{annotation_value}' with prefix '{prefix}' that is not defined in the Prefixes section."
203-
)
214+
return f"Tag '{tag}' has annotation '{annotation_value}' with prefix '{prefix}' that is not defined in the Prefixes section."
204215

205216

206217
@hed_error(

hed/models/base_input.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ class BaseInput:
2121
EXCEL_EXTENSION = [".xlsx"]
2222

2323
def __init__(
24-
self, file, file_type=None, worksheet_name=None, has_column_names=True, mapper=None, name=None, allow_blank_names=True
24+
self,
25+
file,
26+
file_type=None,
27+
worksheet_name=None,
28+
has_column_names=True,
29+
mapper=None,
30+
name=None,
31+
allow_blank_names=True,
2532
):
2633
"""Constructor for the BaseInput class.
2734
@@ -562,7 +569,9 @@ def _load_excel_file(self, file, has_column_names):
562569
loaded_worksheet = self.get_worksheet(self._worksheet_name)
563570
self._dataframe = self._get_dataframe_from_worksheet(loaded_worksheet, has_column_names)
564571
except Exception as e:
565-
raise HedFileError(HedExceptions.INVALID_FILE_FORMAT, f"Failed to load Excel file: {str(e)}", self.name) from e
572+
raise HedFileError(
573+
HedExceptions.INVALID_FILE_FORMAT, f"Failed to load Excel file: {str(e)}", self.name
574+
) from e
566575

567576
def _load_text_file(self, file, pandas_header):
568577
"""Load a text file (TSV/CSV) into a pandas DataFrame.
@@ -611,4 +620,6 @@ def _load_text_file(self, file, pandas_header):
611620
except pd.errors.EmptyDataError:
612621
self._dataframe = pd.DataFrame() # Handle case where file has no data
613622
except Exception as e:
614-
raise HedFileError(HedExceptions.INVALID_FILE_FORMAT, f"Failed to load text file: {str(e)}", self.name) from e
623+
raise HedFileError(
624+
HedExceptions.INVALID_FILE_FORMAT, f"Failed to load text file: {str(e)}", self.name
625+
) from e

hed/models/column_mapper.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,16 @@ def _check_for_duplicates_and_required(self, list_names, column_lists) -> list[d
320320
issues = []
321321
for list_name, col_list in zip(list_names, column_lists, strict=False):
322322
# Convert all known strings to ints, then check for duplicates
323-
converted_list = [item if isinstance(item, int) else self._reverse_column_map.get(item, item) for item in col_list]
323+
converted_list = [
324+
item if isinstance(item, int) else self._reverse_column_map.get(item, item) for item in col_list
325+
]
324326

325327
if col_list != self._optional_tag_columns:
326328
for test_col in converted_list:
327329
if isinstance(test_col, str) and test_col not in self._reverse_column_map:
328-
issues += ErrorHandler.format_error(ValidationErrors.HED_MISSING_REQUIRED_COLUMN, test_col, list_name)
330+
issues += ErrorHandler.format_error(
331+
ValidationErrors.HED_MISSING_REQUIRED_COLUMN, test_col, list_name
332+
)
329333

330334
issues += self._check_for_duplicates_between_lists(
331335
converted_list, list_name, ValidationErrors.DUPLICATE_COLUMN_IN_LIST

hed/models/definition_dict.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ def check_for_definitions(self, hed_string_obj, error_handler=None) -> list[dict
148148

149149
if "/" in def_tag_name or "#" in def_tag_name:
150150
new_def_issues += ErrorHandler.format_error_with_context(
151-
error_handler, DefinitionErrors.INVALID_DEFINITION_EXTENSION, tag=definition_tag, def_name=def_tag_name
151+
error_handler,
152+
DefinitionErrors.INVALID_DEFINITION_EXTENSION,
153+
tag=definition_tag,
154+
def_name=def_tag_name,
152155
)
153156

154157
if new_def_issues:
@@ -294,13 +297,19 @@ def _validate_contents(definition_tag, group, error_handler):
294297
def_keys = {DefTagNames.DEF_KEY, DefTagNames.DEF_EXPAND_KEY, DefTagNames.DEFINITION_KEY}
295298
for def_tag in group.find_tags(def_keys, recursive=True, include_groups=0):
296299
issues += ErrorHandler.format_error_with_context(
297-
error_handler, DefinitionErrors.DEF_TAG_IN_DEFINITION, tag=def_tag, def_name=definition_tag.extension
300+
error_handler,
301+
DefinitionErrors.DEF_TAG_IN_DEFINITION,
302+
tag=def_tag,
303+
def_name=definition_tag.extension,
298304
)
299305

300306
for tag in group.get_all_tags():
301307
if tag.has_attribute(HedKey.Unique) or tag.has_attribute(HedKey.Required):
302308
issues += ErrorHandler.format_error_with_context(
303-
error_handler, DefinitionErrors.BAD_PROP_IN_DEFINITION, tag=tag, def_name=definition_tag.extension
309+
error_handler,
310+
DefinitionErrors.BAD_PROP_IN_DEFINITION,
311+
tag=tag,
312+
def_name=definition_tag.extension,
304313
)
305314

306315
return issues

hed/models/df_util.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ def expand_defs(df, hed_schema, def_dict, columns=None):
7171

7272
for column in columns:
7373
mask = df[column].str.contains("Def/", case=False)
74-
df.loc[mask, column] = df.loc[mask, column].apply(partial(_expand_defs, hed_schema=hed_schema, def_dict=def_dict))
74+
df.loc[mask, column] = df.loc[mask, column].apply(
75+
partial(_expand_defs, hed_schema=hed_schema, def_dict=def_dict)
76+
)
7577

7678

7779
def _convert_to_form(hed_string, hed_schema, tag_form):
@@ -86,7 +88,9 @@ def _expand_defs(hed_string, hed_schema, def_dict):
8688
return str(HedString(hed_string, hed_schema, def_dict).expand_defs())
8789

8890

89-
def process_def_expands(hed_strings, hed_schema, known_defs=None, ambiguous_defs=None) -> tuple["DefinitionDict", dict, dict]:
91+
def process_def_expands(
92+
hed_strings, hed_schema, known_defs=None, ambiguous_defs=None
93+
) -> tuple["DefinitionDict", dict, dict]:
9094
"""Gather def-expand tags in the strings/compare with known definitions to find any differences.
9195
9296
Parameters:
@@ -235,7 +239,9 @@ def split_delay_tags(series, hed_schema, onsets):
235239
return None
236240
split_df = pd.DataFrame({"onset": onsets, "HED": series, "original_index": series.index})
237241
delay_strings = [
238-
(i, HedString(hed_string, hed_schema)) for (i, hed_string) in series.items() if "delay/" in hed_string.casefold()
242+
(i, HedString(hed_string, hed_schema))
243+
for (i, hed_string) in series.items()
244+
if "delay/" in hed_string.casefold()
239245
]
240246
delay_groups = []
241247
for i, delay_string in delay_strings:

hed/models/tabular_input.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ def __init__(self, file=None, sidecar=None, name=None):
3636
"""
3737
if sidecar and not isinstance(sidecar, Sidecar):
3838
sidecar = Sidecar(sidecar)
39-
new_mapper = ColumnMapper(sidecar=sidecar, optional_tag_columns=[self.HED_COLUMN_NAME], warn_on_missing_column=True)
39+
new_mapper = ColumnMapper(
40+
sidecar=sidecar, optional_tag_columns=[self.HED_COLUMN_NAME], warn_on_missing_column=True
41+
)
4042

4143
self._sidecar = sidecar
4244

hed/schema/hed_cache.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ def get_hed_versions(local_hed_directory=None, library_name=None, check_prerelea
134134
return all_hed_versions
135135

136136

137-
def get_hed_version_path(xml_version, library_name=None, local_hed_directory=None, check_prerelease=False) -> Union[str, None]:
137+
def get_hed_version_path(
138+
xml_version, library_name=None, local_hed_directory=None, check_prerelease=False
139+
) -> Union[str, None]:
138140
"""Get HED XML file path in a directory. Only returns filenames that exist.
139141
140142
Parameters:
@@ -226,7 +228,9 @@ def cache_xml_versions(
226228
new_hed_versions = _get_hed_xml_versions_one_library(hed_base_url)
227229
_merge_in_versions(all_hed_versions, new_hed_versions)
228230
for hed_library_url in hed_library_urls:
229-
new_hed_versions = _get_hed_xml_versions_from_url_all_libraries(hed_library_url, skip_folders=skip_folders)
231+
new_hed_versions = _get_hed_xml_versions_from_url_all_libraries(
232+
hed_library_url, skip_folders=skip_folders
233+
)
230234
_merge_in_versions(all_hed_versions, new_hed_versions)
231235

232236
for library_name, hed_versions in all_hed_versions.items():

0 commit comments

Comments
 (0)