Repository navigation
Allow parsing of NUM content items without a measured value - #476
Merged
CPBridge merged 3 commits intoOct 22, 2026
Merged
Conversation
The Measured Value Sequence (0040,A300) of a NUM content item is type 2 and may be empty, in which case the Numeric Value Qualifier Code Sequence (0040,A301) gives the reason for the absence of the value (e.g. "Measurement failure"). Parsing such an item raised an IndexError, which made srread() and the SR from_dataset() methods fail for any document containing one. NumContentItem.from_dataset() now accepts an empty Measured Value Sequence, and the value and unit properties of NumContentItem and Measurement return None in that case. Measurement.from_sequence() now copies the content item instead of passing its value to the constructor, so that measurements without a value can be retrieved via get_measurements().
CPBridge
requested changes
Oct 22, 2026
Comment on lines
+2937
to
+2940
| dataset = Dataset(measurement[0]) | ||
| dataset.MeasuredValueSequence = [] | ||
| item = NumContentItem.from_dataset(dataset) | ||
| retrieved = Measurement.from_sequence([item]) |
Collaborator
There was a problem hiding this comment.
Wouldn't this be a more natural and appropriate test?
Suggested change
| dataset = Dataset(measurement[0]) | |
| dataset.MeasuredValueSequence = [] | |
| item = NumContentItem.from_dataset(dataset) | |
| retrieved = Measurement.from_sequence([item]) | |
| measurement[0].MeasuredValueSequence = [] | |
| retrieved = Measurement.from_sequence(measurement) |
Maybe I am missing something?
Contributor
Author
There was a problem hiding this comment.
No, you're right, that's simpler and it works. Changed in 879b754. The test still fails on master.
Co-authored-by: Chris Bridge <[email protected]>
CPBridge
approved these changes
Oct 22, 2026
Collaborator
|
Looks good, thanks @DG47 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #475
The Measured Value Sequence (0040,A300) of a NUM content item is type 2 and may be empty (PS3.3 Table C.18.1-1, "Zero or one Item shall be included in this Sequence"). In that case the Numeric Value Qualifier Code Sequence (0040,A301) is required and gives the reason for the absence of the value, for example "Measurement failure" or "Not a number" from CID 42. highdicom raised an
IndexErrorwhen decoding such an item, sosrread()andComprehensive3DSR.from_dataset()(and the other SRfrom_dataset()methods) failed for any document that contained one.Changes:
src/highdicom/sr/value_types.py:NumContentItem.from_dataset()only converts the units code when the Measured Value Sequence has an item.NumContentItem.valueandNumContentItem.unitreturnNonewhen the sequence is empty.src/highdicom/sr/templates.py:Measurement.from_sequence()rebuilt the measurement by passingitem.valueanditem.unitto the constructor, which requires a numeric value. It now copies the content item, the same way_MeasurementsAndQualitativeEvaluations.from_sequence()does, soget_measurements()works for measurements without a value.Measurement.valueandMeasurement.unitreturnNonein that case.Construction is unchanged:
NumContentItemandMeasurementstill require a value and a unit. For items that have a measured value, the parsed values are the same as before.Tests (
tests/test_sr.py):NumContentItem.from_dataset()with an empty Measured Value Sequence and a qualifierMeasurement.from_sequence()with and without a measured valueget_planar_roi_measurement_groups()andget_measurements()Three of the new tests fail on master. The one that passes on master covers
Measurement.from_sequence()for a normal measurement and guards the existing behaviour. All new tests pass with this change.Validation:
pytest tests/test_sr.py -k "without_measured_value or without_value or TestMeasurement and from_sequence": 5 passed (3 failed on master)pytest tests: 2042 passed, 153 skippedflake8 --exclude='bin,build,.eggs,.venv': clean