Preserve legacy ndx-pose video references during organize - #1916
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1916 +/- ##
==========================================
+ Coverage 77.35% 77.44% +0.09%
==========================================
Files 89 89
Lines 13325 13397 +72
==========================================
+ Hits 10307 10375 +68
- Misses 3018 3022 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
I added the remaining regression coverage before asking for review: a close/reopen HDF5 persistence test, coverage through The full |
yarikoptic-gitmate
left a comment
There was a problem hiding this comment.
Nice, targeted fix. I checked it beyond just reading the diff: built a real NWB file with an actual ndx-pose PoseEstimation + ImageSeries, ran rename_nwb_external_files end-to-end, and confirmed original_videos and external_file both get renamed and persisted correctly — including with ndx-pose uninstalled (pynwb reconstructs PoseEstimation dynamically from the file's cached namespace spec), which validates the "not a required runtime dependency" claim. The unit tests are thorough on the edge cases that matter (byte/str values, path-separator normalization, URLs left alone, unrelated containers, longer replacement strings for variable-length HDF5 strings).
Two small things before this is good to merge:
- Were the new tests in
test_pynwb_utils.pywritten with AI assistance? If so, perDEVELOPMENT.mdthey should carry the@pytest.mark.ai_generatedmarker, as is done elsewhere in the suite (e.g.test_cmd_validate.py,test_base.py). - Could you extend the
rename_nwb_external_filesdocstring to mention that it now also updates legacyPoseEstimation.original_videosreferences (not justImageSeries.external_file)? Would help future readers who don't dig into_rename_pose_estimation_original_videos.
Otherwise this looks solid to me.
Generated by Claude Code
|
Addressed both points from the review:
The focused utility tests pass locally (7 passed), and the touched files pass the targeted flake8 check. The update is in commit |
4cc085d to
f1a3e99
Compare
|
The code and required checks for #1916 and #1917 are green; the remaining |
yarikoptic-gitmate
left a comment
There was a problem hiding this comment.
Re-reviewed at f1a3e99. Both prior points are addressed — the docstring now documents the original_videos side effect, and all four new tests carry @pytest.mark.ai_generated. The core logic in _rename_pose_estimation_original_videos/_external_reference_key is unchanged from the version I already exercised end-to-end (real ndx-pose file, both with the extension installed and with it uninstalled via pynwb's dynamic-class path), so that verification still stands.
On the performance question specifically: _rename_pose_estimation_original_videos walks nwb.objects.values(), which is the container graph pynwb already fully materializes during the pre-existing io.read() call in this same function — so the scan adds no extra I/O or re-parsing, just an in-memory dict iteration with a cheap getattr per container. I benchmarked this directly: a synthetic file with 5000 containers took ~18s to read() (dominated by pynwb/hdmf construction, unrelated to this PR) versus ~0.5ms to run the new scan over all 5003 resulting objects — over 4 orders of magnitude smaller than the cost the feature already pays to open the file. It's also gated by if not renames: return, so files with no non-URL external-file renames (the common case) skip the scan entirely, and it runs once per file rather than once per renamed path. I don't see an avoidable hit here.
Logic-wise nothing new to flag: matching is still by normalized path string (backslash→forward-slash, bytes decoded) against the exact old→new map built from the ImageSeries rename pass, URLs are skipped on both sides, and non-list original_videos values (missing/str/bytes) are safely skipped.
LGTM.
Generated by Claude Code
|
🚀 PR was released in |
Fixes #1817
Older ndx-pose files can store source-video paths in the deprecated
PoseEstimation.original_videosfield.dandi organize --update-external-file-pathspreviously renamed the linkedImageSeries.external_filevalues but left those legacy strings pointing at the old location.This change reuses the exact source-video old-to-new mapping while an NWB file is open and updates only matching, non-URL
original_videosentries. It identifies the container by itsneurodata_type, so ndx-pose is not a required runtime dependency. Newersource_videolinks and unrelated containers are left untouched.Tests cover path-separator normalization, byte/string values, remote URLs, and unrelated containers.
Validation: focused regression test and flake8 pass.