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

fetch_nwb non-mixin compatability #1201

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ dj.FreeTable(dj.conn(), "common_session.session_group").drop()
- Move cleanup of `IntervalList` orphan entries to cron job cleanup process #1195
- Add mixin method `get_fully_defined_key` #1198


### Pipelines

- Common
Expand All @@ -58,7 +57,7 @@ dj.FreeTable(dj.conn(), "common_session.session_group").drop()
- Export fixes #1164
- Allow `get_abs_path` to add selection entry. #1164
- Log restrictions and joins. #1164
- Check if querying table inherits mixin in `fetch_nwb`. #1192
- Check if querying table inherits mixin in `fetch_nwb`. #1192, #1201
- Ensure externals entries before adding to export. #1192
- Error specificity in `LabMemberInfo` #1192

Expand Down
12 changes: 11 additions & 1 deletion src/spyglass/utils/dj_helper_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ def fetch_nwb(query_expression, nwb_master, *attrs, **kwargs):
nwb_objects : list
List of dicts containing fetch results and NWB objects.
"""
from spyglass.utils.dj_mixin import SpyglassMixin

kwargs["as_dict"] = True # force return as dictionary

tbl, attr_name = nwb_master
Expand All @@ -301,8 +303,16 @@ def fetch_nwb(query_expression, nwb_master, *attrs, **kwargs):
# This also opens the file and stores the file object
get_nwb_file(file_path)

# logging arg only if instanced table inherits Mixin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe at some point this inst piece should be extracted into a helper, or maybe as def is_spymixin(obj) -> bool: - but i'm good with merging as-is

inst = ( # instancing may not be necessary
query_expression()
if isinstance(query_expression, type)
and issubclass(query_expression, dj.Table)
else query_expression
)
arg = dict(log_export=False) if isinstance(inst, SpyglassMixin) else dict()
query_table = query_expression.join(
tbl.proj(nwb2load_filepath=attr_name), log_export=False
tbl.proj(nwb2load_filepath=attr_name), **arg
)
rec_dicts = query_table.fetch(*attrs, **kwargs)
# get filepath for each. Use datajoint for checksum if local
Expand Down
Loading