Skip to content

Commit 5f95b3a

Browse files
committed
BUG: Fix XML loading to convert numeric VR values to proper Python types
pydicom 3.0+ requires numeric VR types (US, SS, UL, SL, FD, FL) to be actual integers/floats, not strings. Updated _load_xml_dataset to convert string values from XML to the appropriate Python type based on VR. This fixes test_load_xml_response which was failing with 'A value of type str cannot be assigned to a tag with VR US'.
1 parent b5540b7 commit 5f95b3a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/dicomweb_client/web.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ def _load_xml_dataset(dataset: Element) -> pydicom.dataset.Dataset:
7474
value = [v.text.strip() for v in value]
7575
else:
7676
value = None
77+
78+
# Convert string values to appropriate Python types for numeric VRs
79+
# to satisfy pydicom 3.0+ stricter type validation
80+
if value is not None and vr in ('US', 'SS', 'UL', 'SL', 'FD', 'FL'):
81+
if isinstance(value, list):
82+
value = [int(v) if vr in ('US', 'SS', 'UL', 'SL') else float(v)
83+
for v in value]
84+
else:
85+
value = int(value) if vr in ('US', 'SS', 'UL', 'SL') else float(value)
86+
7787
setattr(ds, keyword, value)
7888
return ds
7989

0 commit comments

Comments
 (0)