Skip to content

Commit

Permalink
Backport PR #503 on branch 3.x (PR: Update load_dicom to accommodat…
Browse files Browse the repository at this point in the history
…e Pydicom 3.0) (#507)

Co-authored-by: Ryan Clary <[email protected]>
  • Loading branch information
meeseeksmachine and mrclary authored Sep 29, 2024
1 parent b3910e9 commit b7239c2
Show file tree
Hide file tree
Showing 2 changed files with 14 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
6 changes: 5 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,9 @@
"""

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

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


@pytest.mark.skipif(
os.environ.get("USE_CONDA") == "true",
reason="Pydicom is not installed correctly in Conda envs"
)
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 b7239c2

Please sign in to comment.