scripts: copy paired annotations between zarr recordings#397
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
| src_n = _entries(src) | ||
| dst_n_before = _entries(dst) if os.path.exists(dst) else 0 | ||
|
|
||
| print( | ||
| f"[{'dry' if args.dry_run else 'copy'}] {args.name}: " | ||
| f"{src_hash}({src_n}) -> {dst_hash} (had {dst_n_before})" | ||
| ) | ||
| if args.dry_run: | ||
| continue | ||
|
|
||
| if os.path.exists(dst): | ||
| shutil.rmtree(dst) | ||
| shutil.copytree(src, dst) | ||
|
|
||
| verify_n = _entries(dst) | ||
| print(f" verified: n_entries={verify_n}") | ||
| if verify_n != src_n: | ||
| raise SystemExit(f"Mismatch after copy: src={src_n} dst={verify_n}") |
There was a problem hiding this comment.
Silent propagation of corrupted data. If the source zarr array exists but cannot be read (e.g., corrupted), _entries(src) returns -1. The script continues copying, then _entries(dst) also returns -1, and the verification at line 123 passes (-1 == -1), falsely indicating success.
Fix by checking for valid source data:
src_n = _entries(src)
if src_n < 0:
raise SystemExit(f"Source exists but cannot be read as zarr: {src}")| src_n = _entries(src) | |
| dst_n_before = _entries(dst) if os.path.exists(dst) else 0 | |
| print( | |
| f"[{'dry' if args.dry_run else 'copy'}] {args.name}: " | |
| f"{src_hash}({src_n}) -> {dst_hash} (had {dst_n_before})" | |
| ) | |
| if args.dry_run: | |
| continue | |
| if os.path.exists(dst): | |
| shutil.rmtree(dst) | |
| shutil.copytree(src, dst) | |
| verify_n = _entries(dst) | |
| print(f" verified: n_entries={verify_n}") | |
| if verify_n != src_n: | |
| raise SystemExit(f"Mismatch after copy: src={src_n} dst={verify_n}") | |
| src_n = _entries(src) | |
| if src_n < 0: | |
| raise SystemExit(f"Source exists but cannot be read as zarr: {src}") | |
| dst_n_before = _entries(dst) if os.path.exists(dst) else 0 | |
| print( | |
| f"[{'dry' if args.dry_run else 'copy'}] {args.name}: " | |
| f"{src_hash}({src_n}) -> {dst_hash} (had {dst_n_before})" | |
| ) | |
| if args.dry_run: | |
| continue | |
| if os.path.exists(dst): | |
| shutil.rmtree(dst) | |
| shutil.copytree(src, dst) | |
| verify_n = _entries(dst) | |
| print(f" verified: n_entries={verify_n}") | |
| if verify_n != src_n: | |
| raise SystemExit(f"Mismatch after copy: src={src_n} dst={verify_n}") | |
Spotted by Graphite
Is this helpful? React 👍 or 👎 to let us know.
Claude Code ReviewSummaryAdds a one-off utility script to copy a named zarr sub-array (default Key concerns
Suggestions
Verdict: Request ChangesThe script is small and the intent is clear, but writing into zarr stores via Reviewed by Claude · Review workflow |

No description provided.