-
Notifications
You must be signed in to change notification settings - Fork 52
Cleanup source selection in fetch_nwb by defaulting to Nwbfile #1348
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
Conversation
Co-authored-by: samuelbray32 <[email protected]>
Co-authored-by: samuelbray32 <[email protected]>
tests/utils/test_mixin.py
Outdated
| Mixin().fetch_nwb() | ||
| # Should default to Nwbfile instead of raising NotImplementedError | ||
| table, attr = Mixin()._nwb_table_tuple | ||
| from spyglass.common.common_nwbfile import Nwbfile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spyglass imports in tests need to be from fixtures. This should be imported from from the common test fixture
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 81437c6. Changed to use the common fixture instead of direct import.
tests/utils/test_mixin.py
Outdated
| from spyglass.utils import SpyglassMixin | ||
| from spyglass.common.common_nwbfile import AnalysisNwbfile, Nwbfile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to above. Use the utils and common fixtures for these imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 81437c6. Updated to use SpyglassMixin and common fixtures instead of direct imports.
Co-authored-by: samuelbray32 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1348 +/- ##
==========================================
- Coverage 69.66% 69.65% -0.01%
==========================================
Files 103 103
Lines 12532 12531 -1
==========================================
- Hits 8730 8729 -1
Misses 3802 3802 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@samuelbray32 So, this changes the default case, yeah? For a table that (a) as no fk-ref and (b) has no explicitly set
Sorry I'm late to the game on this - could've thought through more carefully when the issue was posted |
|
@CBroz1 That's a good point. Especially with things like parameter tables it could lead to unfortunate things like opening all raw nwb files in the database. It might be better to close this PR for now and revisit |
Summary
Streamlines the
fetch_nwbsource selection logic by defaulting toNwbfilewhen no explicitAnalysisNwbfileforeign key exists, eliminating the need for boilerplate foreign key declarations in many table definitions.Problem
The current
_nwb_table_tuplemethod uses a clunky three-step check:_nwb_tableattribute-> AnalysisNwbfilein table definition-> Nwbfilein table definitionNotImplementedErrorif none foundThis requires explicit foreign key declarations even when
Nwbfile(the most common case) is needed.Solution
Simplified the logic to assume data comes from
NwbfileunlessAnalysisNwbfileforeign key exists:Before:
After:
Key Changes
Nwbfileinstead of failing when no explicit foreign key found_nwb_tableattribute still takes highest priorityBackward Compatibility
✅ Fully backward compatible - all existing table patterns continue to work:
_nwb_table = Nwbfile(unchanged)-> AnalysisNwbfileFK (unchanged)-> NwbfileFK (unchanged)Nwbfileinstead of failing)Benefits
-> Nwbfileto table definitions in common casesfetch_nwbwithout extra configurationFixes #1292.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.