From 89cf1cd3023b4a1e5df9bafff59e2cd9d9e39951 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Sun, 3 Dec 2023 15:38:32 -0500 Subject: [PATCH 1/4] TOX: Enable pydicom@master for dev test --- tox.ini | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tox.ini b/tox.ini index 17a66b04e..d91c136fc 100644 --- a/tox.ini +++ b/tox.ini @@ -99,9 +99,8 @@ deps = full,pre,dev: pillow >=8.1 full,pre,dev: indexed_gzip >=1.4 full,pre,dev: pyzstd >=0.14.3 - full,pre,dev: pydicom >=2.1 - # pydicom master seems to be breaking things - # pre: pydicom @ git+https://github.com/pydicom/pydicom.git@main + full,pre: pydicom >=2.1 + dev: pydicom @ git+https://github.com/pydicom/pydicom.git@main commands = pytest --doctest-modules --doctest-plus \ From 652edd9530e353a3aa20cf7b58c33b21cd110f58 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Sun, 3 Dec 2023 16:02:35 -0500 Subject: [PATCH 2/4] RF: Replace deprecated pydicom.dicomio.read_file with dcmread --- nibabel/nicom/dicomreaders.py | 2 +- nibabel/nicom/dicomwrappers.py | 6 +++--- nibabel/nicom/tests/test_dicomreaders.py | 2 +- nibabel/nicom/tests/test_dicomwrappers.py | 6 +++--- nibabel/pydicom_compat.py | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/nibabel/nicom/dicomreaders.py b/nibabel/nicom/dicomreaders.py index 113af967c..5892bb8db 100644 --- a/nibabel/nicom/dicomreaders.py +++ b/nibabel/nicom/dicomreaders.py @@ -53,7 +53,7 @@ def read_mosaic_dir(dicom_path, globber='*.dcm', check_is_dwi=False, dicom_kwarg If True, raises an error if we don't find DWI information in the DICOM headers. dicom_kwargs : None or dict - Extra keyword arguments to pass to the pydicom ``read_file`` function. + Extra keyword arguments to pass to the pydicom ``dcmread`` function. Returns ------- diff --git a/nibabel/nicom/dicomwrappers.py b/nibabel/nicom/dicomwrappers.py index 572957f39..42d4b1413 100755 --- a/nibabel/nicom/dicomwrappers.py +++ b/nibabel/nicom/dicomwrappers.py @@ -44,9 +44,9 @@ def wrapper_from_file(file_like, *args, **kwargs): filename string or file-like object, pointing to a valid DICOM file readable by ``pydicom`` \*args : positional - args to ``dicom.read_file`` command. + args to ``dicom.dcmread`` command. \*\*kwargs : keyword - args to ``dicom.read_file`` command. ``force=True`` might be a + args to ``dicom.dcmread`` command. ``force=True`` might be a likely keyword argument. Returns @@ -55,7 +55,7 @@ def wrapper_from_file(file_like, *args, **kwargs): DICOM wrapper corresponding to DICOM data type """ with ImageOpener(file_like) as fobj: - dcm_data = pydicom.read_file(fobj, *args, **kwargs) + dcm_data = pydicom.dcmread(fobj, *args, **kwargs) return wrapper_from_data(dcm_data) diff --git a/nibabel/nicom/tests/test_dicomreaders.py b/nibabel/nicom/tests/test_dicomreaders.py index 1e749aced..17ea7430f 100644 --- a/nibabel/nicom/tests/test_dicomreaders.py +++ b/nibabel/nicom/tests/test_dicomreaders.py @@ -41,7 +41,7 @@ def test_passing_kwds(): # This should not raise an error data2, aff2, bs2, gs2 = func(IO_DATA_PATH, dwi_glob, dicom_kwargs=dict(force=True)) assert_array_equal(data, data2) - # This should raise an error in pydicom.dicomio.read_file + # This should raise an error in pydicom.filereader.dcmread with pytest.raises(TypeError): func(IO_DATA_PATH, dwi_glob, dicom_kwargs=dict(not_a_parameter=True)) # These are invalid dicoms, so will raise an error unless force=True diff --git a/nibabel/nicom/tests/test_dicomwrappers.py b/nibabel/nicom/tests/test_dicomwrappers.py index 62076c042..083357537 100755 --- a/nibabel/nicom/tests/test_dicomwrappers.py +++ b/nibabel/nicom/tests/test_dicomwrappers.py @@ -23,8 +23,8 @@ DATA_FILE = pjoin(IO_DATA_PATH, 'siemens_dwi_1000.dcm.gz') DATA_FILE_PHILIPS = pjoin(IO_DATA_PATH, 'philips_mprage.dcm.gz') if have_dicom: - DATA = pydicom.read_file(gzip.open(DATA_FILE)) - DATA_PHILIPS = pydicom.read_file(gzip.open(DATA_FILE_PHILIPS)) + DATA = pydicom.dcmread(gzip.open(DATA_FILE)) + DATA_PHILIPS = pydicom.dcmread(gzip.open(DATA_FILE_PHILIPS)) else: DATA = None DATA_PHILIPS = None @@ -170,7 +170,7 @@ def test_wrapper_from_data(): @dicom_test def test_wrapper_args_kwds(): - # Test we can pass args, kwargs to read_file + # Test we can pass args, kwargs to dcmread dcm = didw.wrapper_from_file(DATA_FILE) data = dcm.get_data() # Passing in non-default arg for defer_size diff --git a/nibabel/pydicom_compat.py b/nibabel/pydicom_compat.py index 4d9df7df7..ce6f8fe8c 100644 --- a/nibabel/pydicom_compat.py +++ b/nibabel/pydicom_compat.py @@ -35,7 +35,7 @@ if have_dicom: # Values not imported by default import pydicom.values # type: ignore - from pydicom.dicomio import read_file # noqa:F401 + from pydicom.dicomio import dcmread as read_file # noqa:F401 from pydicom.sequence import Sequence # noqa:F401 tag_for_keyword = pydicom.datadict.tag_for_keyword From 32d9cd356d2ad540fc28e5d2fd7a03e5cb7889b3 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Sun, 3 Dec 2023 16:07:27 -0500 Subject: [PATCH 3/4] MNT: Deprecate unused pydicom_compat module --- nibabel/pydicom_compat.py | 8 ++++++++ nibabel/tests/test_removalschedule.py | 1 + 2 files changed, 9 insertions(+) diff --git a/nibabel/pydicom_compat.py b/nibabel/pydicom_compat.py index ce6f8fe8c..fae24e691 100644 --- a/nibabel/pydicom_compat.py +++ b/nibabel/pydicom_compat.py @@ -21,11 +21,19 @@ """ from __future__ import annotations +import warnings from typing import Callable from .deprecated import deprecate_with_version from .optpkg import optional_package +warnings.warn( + "We will remove the 'pydicom_compat' module from nibabel 7.0. " + "Please consult pydicom's documentation for any future needs.", + DeprecationWarning, + stacklevel=2, +) + pydicom, have_dicom, _ = optional_package('pydicom') read_file: Callable | None = None diff --git a/nibabel/tests/test_removalschedule.py b/nibabel/tests/test_removalschedule.py index b11a62180..772d395fd 100644 --- a/nibabel/tests/test_removalschedule.py +++ b/nibabel/tests/test_removalschedule.py @@ -6,6 +6,7 @@ from ..pkg_info import cmp_pkg_version MODULE_SCHEDULE = [ + ('7.0.0', ['nibabel.pydicom_compat']), ('5.0.0', ['nibabel.keywordonly', 'nibabel.py3k']), ('4.0.0', ['nibabel.trackvis']), ('3.0.0', ['nibabel.minc', 'nibabel.checkwarns']), From c367345b98f5ba6e664fbcf30498e7e8f2aa1054 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Sun, 3 Dec 2023 16:44:41 -0500 Subject: [PATCH 4/4] FIX: read_file -> dcmread --- nibabel/dft.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nibabel/dft.py b/nibabel/dft.py index 7a49d49f5..ee34595b3 100644 --- a/nibabel/dft.py +++ b/nibabel/dft.py @@ -238,7 +238,7 @@ def __getattribute__(self, name): return val def dicom(self): - return pydicom.read_file(self.files[0]) + return pydicom.dcmread(self.files[0]) def _get_subdirs(base_dir, files_dict=None, followlinks=False): @@ -347,7 +347,7 @@ def _update_dir(c, dir, files, studies, series, storage_instances): def _update_file(c, path, fname, studies, series, storage_instances): try: - do = pydicom.read_file(f'{path}/{fname}') + do = pydicom.dcmread(f'{path}/{fname}') except pydicom.filereader.InvalidDicomError: logger.debug(' not a DICOM file') return None