-
Notifications
You must be signed in to change notification settings - Fork 25
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
Error on NWB files with external links #843
Conversation
Codecov Report
@@ Coverage Diff @@
## master #843 +/- ##
==========================================
+ Coverage 85.28% 85.35% +0.07%
==========================================
Files 61 61
Lines 6322 6366 +44
==========================================
+ Hits 5392 5434 +42
- Misses 930 932 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
@yarikoptic The tests appear to be failing because this call to @bendichter What's the best way to copy an NWB file while giving it a new |
@metadata_cache.memoize_path | ||
def nwb_has_external_links(filepath): | ||
with h5py.File(filepath, "r") as fp: | ||
visited = set() | ||
|
||
# cannot use `file.visititems` because it skips external links | ||
# (https://github.com/h5py/h5py/issues/671) | ||
def visit(path="/"): | ||
if isinstance(fp[path], h5py.Group): | ||
for key in fp[path].keys(): | ||
key_path = path + "/" + key | ||
if key_path not in visited: | ||
visited.add(key_path) | ||
if isinstance( | ||
fp.get(key_path, getlink=True), h5py.ExternalLink | ||
) or visit(key_path): | ||
return True | ||
elif isinstance(fp.get(path, getlink=True), h5py.ExternalLink): | ||
return True | ||
return False | ||
|
||
return visit() |
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.
Ah yes, thank you for tidying up this function.
pinged @rly on slack |
I think a combination of the If you just want to resolve external links, the |
How exactly do I combine those two functions? If I try doing this: with pynwb.NWBHDF5IO(src, "r") as ior, pynwb.NWBHDF5IO(dest, "w") as iow:
data = ior.read()
data.generate_new_id()
iow.export(container=data) I get If I instead do this: with pynwb.NWBHDF5IO(src, "r") as ior, pynwb.NWBHDF5IO(dest, "w") as iow:
data = ior.read()
data.generate_new_id()
iow.export(src_io=ior) then the copy will still have the same object ID as the original. If I do this: with pynwb.NWBHDF5IO(src, "r") as ior, pynwb.NWBHDF5IO(dest, "w") as iow:
ior.generate_new_id()
iow.export(src_io=ior) then I get |
Please try: with pynwb.NWBHDF5IO(src, "r") as ior, pynwb.NWBHDF5IO(dest, "w") as iow:
data = ior.read()
data.generate_new_id()
iow.export(ior, container=data) |
@rly That fails with " |
My bad. 'container' is the argument name for with pynwb.NWBHDF5IO(src, "r") as ior, pynwb.NWBHDF5IO(dest, "w") as iow:
data = ior.read()
data.generate_new_id()
iow.export(ior, nwbfile=data) |
@rly That works; thanks. |
tox.ini is very popular today - keeps conflicting |
) or visit(key_path): | ||
return True | ||
elif isinstance(fp.get(path, getlink=True), h5py.ExternalLink): | ||
return True |
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.
@bendichter what use case could trigger this codepath? would be nice to add it to the test
@yarikoptic Conflict resolved. |
ok, let's proceed with it as is. Thank you! |
Closes #840.