Skip to content

Commit 2987880

Browse files
authored
Merge pull request #1280 from effigies/mnt/deprecate-pydicom_compat
MNT: Deprecate nibabel.pydicom_compat
2 parents 96abe5a + c367345 commit 2987880

8 files changed

+22
-14
lines changed

nibabel/dft.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def __getattribute__(self, name):
238238
return val
239239

240240
def dicom(self):
241-
return pydicom.read_file(self.files[0])
241+
return pydicom.dcmread(self.files[0])
242242

243243

244244
def _get_subdirs(base_dir, files_dict=None, followlinks=False):
@@ -347,7 +347,7 @@ def _update_dir(c, dir, files, studies, series, storage_instances):
347347

348348
def _update_file(c, path, fname, studies, series, storage_instances):
349349
try:
350-
do = pydicom.read_file(f'{path}/{fname}')
350+
do = pydicom.dcmread(f'{path}/{fname}')
351351
except pydicom.filereader.InvalidDicomError:
352352
logger.debug(' not a DICOM file')
353353
return None

nibabel/nicom/dicomreaders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def read_mosaic_dir(dicom_path, globber='*.dcm', check_is_dwi=False, dicom_kwarg
5353
If True, raises an error if we don't find DWI information in the
5454
DICOM headers.
5555
dicom_kwargs : None or dict
56-
Extra keyword arguments to pass to the pydicom ``read_file`` function.
56+
Extra keyword arguments to pass to the pydicom ``dcmread`` function.
5757
5858
Returns
5959
-------

nibabel/nicom/dicomwrappers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ def wrapper_from_file(file_like, *args, **kwargs):
4444
filename string or file-like object, pointing to a valid DICOM
4545
file readable by ``pydicom``
4646
\*args : positional
47-
args to ``dicom.read_file`` command.
47+
args to ``dicom.dcmread`` command.
4848
\*\*kwargs : keyword
49-
args to ``dicom.read_file`` command. ``force=True`` might be a
49+
args to ``dicom.dcmread`` command. ``force=True`` might be a
5050
likely keyword argument.
5151
5252
Returns
@@ -55,7 +55,7 @@ def wrapper_from_file(file_like, *args, **kwargs):
5555
DICOM wrapper corresponding to DICOM data type
5656
"""
5757
with ImageOpener(file_like) as fobj:
58-
dcm_data = pydicom.read_file(fobj, *args, **kwargs)
58+
dcm_data = pydicom.dcmread(fobj, *args, **kwargs)
5959
return wrapper_from_data(dcm_data)
6060

6161

nibabel/nicom/tests/test_dicomreaders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_passing_kwds():
4141
# This should not raise an error
4242
data2, aff2, bs2, gs2 = func(IO_DATA_PATH, dwi_glob, dicom_kwargs=dict(force=True))
4343
assert_array_equal(data, data2)
44-
# This should raise an error in pydicom.dicomio.read_file
44+
# This should raise an error in pydicom.filereader.dcmread
4545
with pytest.raises(TypeError):
4646
func(IO_DATA_PATH, dwi_glob, dicom_kwargs=dict(not_a_parameter=True))
4747
# These are invalid dicoms, so will raise an error unless force=True

nibabel/nicom/tests/test_dicomwrappers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
DATA_FILE = pjoin(IO_DATA_PATH, 'siemens_dwi_1000.dcm.gz')
2424
DATA_FILE_PHILIPS = pjoin(IO_DATA_PATH, 'philips_mprage.dcm.gz')
2525
if have_dicom:
26-
DATA = pydicom.read_file(gzip.open(DATA_FILE))
27-
DATA_PHILIPS = pydicom.read_file(gzip.open(DATA_FILE_PHILIPS))
26+
DATA = pydicom.dcmread(gzip.open(DATA_FILE))
27+
DATA_PHILIPS = pydicom.dcmread(gzip.open(DATA_FILE_PHILIPS))
2828
else:
2929
DATA = None
3030
DATA_PHILIPS = None
@@ -170,7 +170,7 @@ def test_wrapper_from_data():
170170

171171
@dicom_test
172172
def test_wrapper_args_kwds():
173-
# Test we can pass args, kwargs to read_file
173+
# Test we can pass args, kwargs to dcmread
174174
dcm = didw.wrapper_from_file(DATA_FILE)
175175
data = dcm.get_data()
176176
# Passing in non-default arg for defer_size

nibabel/pydicom_compat.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,19 @@
2121
"""
2222
from __future__ import annotations
2323

24+
import warnings
2425
from typing import Callable
2526

2627
from .deprecated import deprecate_with_version
2728
from .optpkg import optional_package
2829

30+
warnings.warn(
31+
"We will remove the 'pydicom_compat' module from nibabel 7.0. "
32+
"Please consult pydicom's documentation for any future needs.",
33+
DeprecationWarning,
34+
stacklevel=2,
35+
)
36+
2937
pydicom, have_dicom, _ = optional_package('pydicom')
3038

3139
read_file: Callable | None = None
@@ -35,7 +43,7 @@
3543
if have_dicom:
3644
# Values not imported by default
3745
import pydicom.values # type: ignore
38-
from pydicom.dicomio import read_file # noqa:F401
46+
from pydicom.dicomio import dcmread as read_file # noqa:F401
3947
from pydicom.sequence import Sequence # noqa:F401
4048

4149
tag_for_keyword = pydicom.datadict.tag_for_keyword

nibabel/tests/test_removalschedule.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from ..pkg_info import cmp_pkg_version
77

88
MODULE_SCHEDULE = [
9+
('7.0.0', ['nibabel.pydicom_compat']),
910
('5.0.0', ['nibabel.keywordonly', 'nibabel.py3k']),
1011
('4.0.0', ['nibabel.trackvis']),
1112
('3.0.0', ['nibabel.minc', 'nibabel.checkwarns']),

tox.ini

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,8 @@ deps =
9999
full,pre,dev: pillow >=8.1
100100
full,pre,dev: indexed_gzip >=1.4
101101
full,pre,dev: pyzstd >=0.14.3
102-
full,pre,dev: pydicom >=2.1
103-
# pydicom master seems to be breaking things
104-
# pre: pydicom @ git+https://github.com/pydicom/pydicom.git@main
102+
full,pre: pydicom >=2.1
103+
dev: pydicom @ git+https://github.com/pydicom/pydicom.git@main
105104

106105
commands =
107106
pytest --doctest-modules --doctest-plus \

0 commit comments

Comments
 (0)