Skip to content

Commit d8a7073

Browse files
authored
PR: Update load_dicom to accommodate Pydicom 3.0 (#503)
1 parent 1d7201c commit d8a7073

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

spyder_kernels/utils/iofuncs.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,16 @@ def load_dicom(filename):
506506

507507
name = osp.splitext(osp.basename(filename))[0]
508508
try:
509-
data = dicomio.read_file(filename, force=True)
509+
# For Pydicom 3/Python 3.10+
510+
data = dicomio.dcmread(filename, force=True)
510511
except TypeError:
511-
data = dicomio.read_file(filename)
512+
data = dicomio.dcmread(filename)
513+
except AttributeError:
514+
# For Pydicom 2/Python 3.9-
515+
try:
516+
data = dicomio.read_file(filename, force=True)
517+
except TypeError:
518+
data = dicomio.read_file(filename)
512519
arr = data.pixel_array
513520
return {name: arr}, None
514521
except Exception as error:

spyder_kernels/utils/tests/test_iofuncs.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
"""
1212

1313
# Standard library imports
14+
import copy
1415
import io
1516
import os
16-
import copy
1717

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

352352

353+
@pytest.mark.skipif(
354+
os.environ.get("USE_CONDA") == "true",
355+
reason="Pydicom is not installed correctly in Conda envs"
356+
)
353357
def test_load_dicom_files():
354358
"""Check that we can load DICOM files."""
355359
# This test pass locally but we need to set the variable below for it to

0 commit comments

Comments
 (0)