Repository navigation
BUG: Fix itk.imread KeyError on unknown ImageIO component type - #7151
hjmjohnson merged 1 commit into
Conversation
[Medium impact] The PR appears safe to merge, with a non-blocking correction needed to the shared error guidance. Findings
|
hjmjohnson
left a comment
There was a problem hiding this comment.
Thank you for tracking this down. The KeyError: 'unknown' is real, and the report is clear. I am requesting changes because the float fallback does not give the result the description promises, it changes what fallback_only=True does, and the test does not exercise the case it is named for. Details are in the line comments.
Points outside the changed lines
- The
.mhaexample in the description. For anElementTypeit cannot interpret,MetaImageIOsets the pixel type toUNKNOWNPIXELTYPEas well (itkMetaImageIO.cxx:146-151). With this PR,_pixelTypeFromIOthen raisesRuntimeError("Unknown pixel type: unknown.")(template_class.py:296), so that file still fails, with a different exception and no image. - Commits. The second commit only repairs the first, so please squash them. The first commit's body is 14 lines; ITK's cap is 12 (Documentation/AI/prose-budget.md), and its last paragraph restates the diff.
- Greptile's docstring thread is marked resolved but is only partly addressed; see the comment on the module docstring.
- Non-blocking, description: the visible text is well over the three-sentence budget in prose-budget.md; the long sections belong in
<details>blocks. The verification section says the change was run only against a 5.4.7 wheel with one file overwritten. CI has since run the new test in an ITK build, which is the result that counts. - Non-blocking question: if an AI assistant helped write this, Documentation/AI/pull-requests.md asks for the PR to be opened as a draft with a short disclosure in a collapsed block.
Findings marked "reasoned from the code" were not run in a build.
|
Addressed all five inline, and squashed the two commits since the second only repaired the first, like you pointed out. On the .mha example: the failure mode now matches what you predicted for a real unknown type. itk.imread() on that file raises a KeyError naming the component type and pointing at pixel_type=, instead of the old bare KeyError('unknown'). Still no image, since the type really is unrecognized, and the new test checks exactly this against a real .mha, not a mock. |
62db918 to
2310dea
Compare
An ImageIO that cannot interpret a file's component type reports
"unknown", for which itk.imread raised KeyError('unknown') with no hint
of the cause or the remedy.
The exception stays a KeyError, because itk.imread retries on KeyError
under fallback_only=True. The advice names a typed reader as well as
pixel_type=, because itk.ImageFileReader.New and the series and mesh
readers reach the same code and take no pixel_type argument.
08596b0 to
1b1af40
Compare
|
@SID-6921 thank you for the quick rework. To save another round I pushed the remaining small items to your branch myself; you are still the author of the commit. Nothing else is needed from you unless you disagree with a change. What changed in this push (content only, same base)
Checked against a local ITK 6.0.0 Python build: the test passes with these changes and fails on unmodified One request: the PR description still describes the earlier float fallback and the mocked PNG test. Could you update it to match the code, or say if you would like me to? |
Requested changes are addressed in 1b1af40; dismissing my change request.
|
Updated the description to match: dropped the float fallback and mocked PNG test references, described the actual KeyError plus typed-reader advice and the real .mha test. Thanks for pushing the rework directly, agreed on all of it. |
An ImageIO that cannot interpret a file's component type reports "unknown", which
itk.imreadpreviously surfaced as a bareKeyError('unknown')with no indication of the cause or the remedy.The component-type lookup now raises a
KeyErrornaming the reported type and pointing atpixel_type=and at building a typed reader directly (itk.ImageFileReader.New,itk.ImageSeriesReader.New, anditk.MeshFileReader.Newall reach this same code path and take nopixel_type=argument)._pixelTypeFromIO's matching branch, shared withitk.meshread, gets the same message for an unrecognized pixel type.fallback_only=Truestill retries onKeyErrorand still fails afterward, since no wrapped reader can decode a component type the ImageIO never identified.The regression test writes a
.mhafile with anElementTypeMetaIO cannot interpret, exercising the real ImageIO rather than a mock, and checks that thefallback_only=Trueretry also fails.