Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update HERD.get_key to replace ValueError with return values #964

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/hdmf/common/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,12 @@ def add_ref_term_set(self, **kwargs):
'doc': ('The field of the compound data type using an external resource.')})
def get_key(self, **kwargs):
"""
Return a Key.
Get a Key by name

If container, relative_path, and field are provided, the Key that corresponds to the given name of the key
for the given container, relative_path, and field is returned.

:returns: Single Key object, or a list of Key objects, or None, depending on how many Keys match the query
"""
key_name, container, relative_path, field = popargs('key_name', 'container', 'relative_path', 'field', kwargs)
key_idx_matches = self.keys.which(key=key_name)
Expand All @@ -503,15 +505,13 @@ def get_key(self, **kwargs):
key_idx = self.object_keys['keys_idx', row_idx]
if key_idx in key_idx_matches:
return self.keys.row[key_idx]
msg = "No key found with that container."
raise ValueError(msg)
return None
else:
if len(key_idx_matches) == 0:
# the key has never been used before
raise ValueError("key '%s' does not exist" % key_name)
return None
elif len(key_idx_matches) > 1:
msg = "There are more than one key with that name. Please search with additional information."
raise ValueError(msg)
return [self.keys.row[ki] for ki in key_idx_matches]
else:
return self.keys.row[key_idx_matches[0]]

Expand Down
Loading