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

Refactor DTR warning #917

Merged
merged 4 commits into from
Aug 12, 2023
Merged

Refactor DTR warning #917

merged 4 commits into from
Aug 12, 2023

Conversation

rly
Copy link
Contributor

@rly rly commented Jul 25, 2023

Motivation

Currently AbstractContainer performs a check for type(child).__name__=='DynamicTableRegion'. While this currently works, it is not ideal to have DTR-specific code in AbstractContainer and it only matches based on class name, not class type. This code is harder to find and does not work well for subclasses of DynamicTableRegion.

In addition, the check is not comprehensive in covering the possible situations in which it is useful. It only checks whether the referred-to table has a parent. The referred-to table may have a parent, but that parent may not have a parent. e.g. in NWB, a PlaneSegmentation may have an ImageSegmentation parent and that ImageSegmentation parent may have a ProcessingModule parent but that ProcessingModule may not have been added to the NWBFile.

See #891 and #885

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 review from mavaylon1 and oruebel July 25, 2023 04:16
@codecov
Copy link

codecov bot commented Jul 25, 2023

Codecov Report

Patch coverage: 91.30% and no project coverage change.

Comparison is base (dd39b38) 88.34% compared to head (9d27cef) 88.34%.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #917   +/-   ##
=======================================
  Coverage   88.34%   88.34%           
=======================================
  Files          45       45           
  Lines        9292     9310   +18     
  Branches     2653     2658    +5     
=======================================
+ Hits         8209     8225   +16     
- Misses        765      766    +1     
- Partials      318      319    +1     
Files Changed Coverage Δ
src/hdmf/common/table.py 85.49% <83.33%> (-0.04%) ⬇️
src/hdmf/container.py 91.60% <100.00%> (+0.05%) ⬆️

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

@mavaylon1
Copy link
Contributor

@rly this slipped by. I'll review today.

# 1) if the table was read from a written file, no need to validate further
p = self.table
while p is not None:
if p.container_source is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

@rly what's the difference between parent and container source? Is the source meant to be the root?

Copy link
Contributor

Choose a reason for hiding this comment

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

This checks if the table being used in the DTR has a source, if it does then pass, if not then it will check the parent for a source (and so on)

Copy link
Contributor

Choose a reason for hiding this comment

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

Container_source ==> path to the file ==>Does zarrio set container_source (confirm?)

Copy link
Contributor

Choose a reason for hiding this comment

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

container_source is set in BuildManager.build . ZarrIO deals with read/write of Builders, but the logic for creating Containters is the same as in HDMF, i.e., HDMF is setting the container_source and the logic to do so is independent of whether HDF5IO or ZarrIO is being used.

table_ancestor_ids = [id(x) for x in self.table.get_ancestors()]
self_ancestor_ids = [id(x) for x in self.get_ancestors()]

if set(table_ancestor_ids).isdisjoint(self_ancestor_ids):
Copy link
Contributor

Choose a reason for hiding this comment

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

This will check to see of the table and the DTR have some shared ancestor, aka check that its in the same file. If not then it'll be an external link and a warning will be thrown but it will be allowed to write. Correct?

@mavaylon1 mavaylon1 self-requested a review August 12, 2023 20:32
@mavaylon1 mavaylon1 merged commit be52652 into dev Aug 12, 2023
25 of 26 checks passed
@rly rly deleted the refactor_dtr_warning branch October 3, 2023 16:53
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.

3 participants