Skip to content

Commit

Permalink
Update load_dicom to accommodate pydicom>=3.0/python>=3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
mrclary committed Sep 27, 2024
1 parent 899c3ea commit 372a774
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 9 additions & 2 deletions spyder_kernels/utils/iofuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,16 @@ def load_dicom(filename):

name = osp.splitext(osp.basename(filename))[0]
try:
data = dicomio.read_file(filename, force=True)
# For Pydicom 3/Python 3.10+
data = dicomio.dcmread(filename, force=True)
except TypeError:
data = dicomio.read_file(filename)
data = dicomio.dcmread(filename)
except AttributeError:
# For Pydicom 2/Python 3.9-
try:
data = dicomio.read_file(filename, force=True)
except TypeError:
data = dicomio.read_file(filename)
arr = data.pixel_array
return {name: arr}, None
except Exception as error:
Expand Down
7 changes: 6 additions & 1 deletion spyder_kernels/utils/tests/test_iofuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
"""

# Standard library imports
import copy
import io
import os
import copy
import sys

# Third party imports
from PIL import ImageFile
Expand Down Expand Up @@ -350,6 +351,10 @@ def test_save_load_hdf5_files(tmp_path):
assert repr(iofuncs.load_hdf5(h5_file)) == repr(expected)


@pytest.mark.skipif(
sys.version_info < (3, 10, 0),
reason="pydicom 3.0 is incompatible with Python < 3.10"
)
def test_load_dicom_files():
"""Check that we can load DICOM files."""
# This test pass locally but we need to set the variable below for it to
Expand Down

0 comments on commit 372a774

Please sign in to comment.