From 84c5285c18aab904e275490f477e55f8b7a29514 Mon Sep 17 00:00:00 2001 From: bpinsard Date: Tue, 24 Sep 2024 11:33:21 -0400 Subject: [PATCH 1/2] fix none value --- src/dcmstack/extract.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/dcmstack/extract.py b/src/dcmstack/extract.py index 38142d0..0d3059b 100644 --- a/src/dcmstack/extract.py +++ b/src/dcmstack/extract.py @@ -9,7 +9,7 @@ from collections import OrderedDict except ImportError: from ordereddict import OrderedDict - + try: import pydicom from pydicom.datadict import keyword_for_tag @@ -410,7 +410,9 @@ def _get_elem_value(self, elem): else: #Otherwise, just take a copy if the value is a list n_vals = elem.VM - if n_vals > 1: + if n_vals == 0: + return None + elif n_vals > 1: value = elem.value[:] else: value = elem.value From 2f71eca698173932c4cc38a2b3420649158999ef Mon Sep 17 00:00:00 2001 From: cneuromod_bot Date: Tue, 19 Nov 2024 12:10:12 -0500 Subject: [PATCH 2/2] add testing for None value --- test/test_extract.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/test_extract.py b/test/test_extract.py index ea54429..4d2edad 100644 --- a/test/test_extract.py +++ b/test/test_extract.py @@ -53,7 +53,7 @@ def test_parse_phx_line(self): assert extract._parse_phoenix_line("test = 0x2") == ('test', 2) assert extract._parse_phoenix_line("test = 2.") == ('test', 2.0) - + with pytest.raises(extract.PhoenixParseError): extract._parse_phoenix_line('test = blah') with pytest.raises(extract.PhoenixParseError): @@ -89,7 +89,9 @@ def test_get_elem_value(self): extractor = extract.MetaExtractor(ignore_rules=ignore_rules) for elem in self.data: value = extractor._get_elem_value(elem) - if elem.VM > 1: + if elem.VM == 0: + assert(value is None) + elif elem.VM > 1: assert(isinstance(value, list)) if elem.VR in list(extract.unpack_vr_map) + ['DS', 'IS']: if elem.VM == 1: