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

Add target_tables argument to DynamicTable.__init__ #971

Merged
merged 3 commits into from
Oct 24, 2023
Merged

Add target_tables argument to DynamicTable.__init__ #971

merged 3 commits into from
Oct 24, 2023

Conversation

rly
Copy link
Contributor

@rly rly commented Oct 24, 2023

Motivation

In a previous PR, we added the ability to specify the target table for a pre-defined DynamicTableRegion column in DynamicTable.__init__ but this was only in generated subclasses of DynamicTable. This functionality works well, but could be useful to build in to DynamicTable in case users want to write their own custom subclass of DynamicTable and want to reuse this generic behavior (such as in pynwb and in extensions). Though in PyNWB, we often have a more specific constructor argument for this: https://github.com/NeurodataWithoutBorders/pynwb/blob/dev/src/pynwb/misc.py#L160 and some hacky code in add_row to handle setting the target table when the first row is added: https://github.com/NeurodataWithoutBorders/pynwb/blob/dev/src/pynwb/misc.py#L207

So I moved the functionality from the custom class generator for generated DynamicTable subclasses to the base DynamicTable itself.

This also has the benefit of fixing #970 when there are multiple chains of hierarchy below DynamicTable. Fixes #970.

We can optionally adjust pynwb to reuse this behavior in the Units table and elsewhere.

How to test the behavior?

pytest

Checklist

  • Did you update CHANGELOG.md with your changes?
  • Have you checked our Contributing document?
  • Have you ensured the PR clearly describes the problem and the solution?
  • Is your contribution compliant with our coding style? This can be checked running ruff from the source directory.
  • Have you checked to ensure that there aren't other open Pull Requests for the same change?
  • Have you included the relevant issue number using "Fix #XXX" notation where XXX is the issue number? By including "Fix #XXX" you allow GitHub to close issue #XXX when the PR is merged.

@rly rly requested a review from oruebel October 24, 2023 02:13
@codecov
Copy link

codecov bot commented Oct 24, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (afd1882) 88.57% compared to head (94a10dc) 88.58%.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #971      +/-   ##
==========================================
+ Coverage   88.57%   88.58%   +0.01%     
==========================================
  Files          45       45              
  Lines        9400     9395       -5     
  Branches     2673     2673              
==========================================
- Hits         8326     8323       -3     
+ Misses        759      758       -1     
+ Partials      315      314       -1     
Files Coverage Δ
src/hdmf/common/io/table.py 79.71% <100.00%> (-4.13%) ⬇️
src/hdmf/common/table.py 86.38% <100.00%> (+0.44%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@oruebel oruebel left a comment

Choose a reason for hiding this comment

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

Overall, the approach looks fine to me. However, the specific use I think may be a bit tricky to understand at first, so I think we should make sure to clearly define when to use target_table vs. when to use the columns argument of DynamicTable.__init__.

@rly
Copy link
Contributor Author

rly commented Oct 24, 2023

Thanks for the quick review!

Copy link
Contributor

@oruebel oruebel left a comment

Choose a reason for hiding this comment

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

Thanks for the clarifications in the text. The PR looks good to me.

@rly rly merged commit c00ae11 into dev Oct 24, 2023
26 checks passed
@rly rly deleted the target_tables branch October 24, 2023 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Auto-generating subclass of subclass of DynamicTable with DTR fails
2 participants