Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix none value in dicom tag. #93

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/dcmstack/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from collections import OrderedDict
except ImportError:
from ordereddict import OrderedDict

try:
import pydicom
from pydicom.datadict import keyword_for_tag
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions test/test_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down