Skip to content
2 changes: 1 addition & 1 deletion docs/source/api2.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
HED API reference (Auto style)
========================
==============================

.. currentmodule:: hed

Expand Down
6 changes: 4 additions & 2 deletions hed/models/base_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
20 changes: 13 additions & 7 deletions hed/models/column_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions hed/models/definition_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 5 additions & 5 deletions hed/models/df_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions hed/models/hed_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions hed/models/hed_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions hed/models/hed_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,12 @@ 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.

"""
if self._schema_entry:
tag_entry = None
Expand All @@ -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.

"""
Expand Down
16 changes: 10 additions & 6 deletions hed/models/sidecar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand All @@ -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 {}
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 9 additions & 5 deletions hed/models/spreadsheet_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion hed/schema/hed_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []
Expand Down
27 changes: 15 additions & 12 deletions hed/schema/hed_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from hed.errors import ErrorHandler
from hed.errors.error_types import ValidationErrors


class HedSchema:
""" A HED schema suitable for processing. """

Expand Down Expand Up @@ -93,15 +94,16 @@ 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:
# make sure it's the last attribute(just to make sure it's in an order)
header_attributes.pop(constants.UNMERGED_ATTRIBUTE, None)
header_attributes[constants.UNMERGED_ATTRIBUTE] = "True"


return header_attributes

def schema_for_namespace(self, namespace):
Expand Down Expand Up @@ -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.

Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
return section._create_tag_entry(long_tag_name)
4 changes: 2 additions & 2 deletions hed/schema/hed_schema_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions hed/schema/hed_schema_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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).
Expand Down
13 changes: 6 additions & 7 deletions hed/schema/schema_io/schema_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Loading