-
Notifications
You must be signed in to change notification settings - Fork 27
Add container deepcopy #108
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
base: dev
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #108 +/- ##
==========================================
+ Coverage 67.04% 67.17% +0.13%
==========================================
Files 24 24
Lines 4870 4890 +20
Branches 1103 1106 +3
==========================================
+ Hits 3265 3285 +20
Misses 1243 1243
Partials 362 362
Continue to review full report at Codecov.
|
1 similar comment
Codecov Report
@@ Coverage Diff @@
## dev #108 +/- ##
==========================================
+ Coverage 67.04% 67.17% +0.13%
==========================================
Files 24 24
Lines 4870 4890 +20
Branches 1103 1106 +3
==========================================
+ Hits 3265 3285 +20
Misses 1243 1243
Partials 362 362
Continue to review full report at Codecov.
|
| # resolve HDMFDataset after and separately because DataIO can wrap an HDMFDataset | ||
| for k, v in cp.__dict__.items(): | ||
| if isinstance(v, HDMFDataset): | ||
| setattr(cp, k, v.dataset) |
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.
On read v.dataset may be and h5py.Dataset with references. I think the resolution for this would be something like
if len(v) > 0 and isinstance(v[0], Container):
setattr(cp, k, [find_copied_container(c) for c in v])
else:
setattr(cp, k, v.dataset)
where find_copied_container would need to replace the reference with the new copy. Not sure, what would happen if you tried to call deepcopy on, e.g., a single DynamicTable that contains references, as in this case those containers may not have been copied yet by deepcopy.
Also, I'm not sure what happens when the container that is being copied was loaded from a file. In this case you may have h5py.Dataset objects that would need to be replaced as well (or are those all wrapped?).
|
Hello, |
|
@francois-ecm thanks for the feedback. I agree, the deepcopy function would be a good way for doing this. We are still working through some cases on the deepcopy functionality. Given other ongoing items I'd expect that it may take a few more weeks for this PR. For appending to a file PyNWB currently supports: 1) adding new containers (e.g,. TimeSeries), and 2) updating existing fields stored in h5py.Datasets. If that is what you need to do, then the following may be a possible solution for your case in the meantime: Updating of attributes is currently not yet supported. I'm not sure how hard it would be to make this work, but if that is what you need to do, then I'd suggest to open an issue describing your use-case so that we can discuss this. |
Fix #65 and adds generally useful functionality
This adds a
Container.__deepcopy__ functionwhich:parentto Nonecontainer_sourceto Noneobject_idmodifiedto Trueparentto itself