Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT: Deprecate nibabel.pydicom_compat #1280

Merged
merged 4 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nibabel/dft.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion nibabel/nicom/dicomreaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down
6 changes: 3 additions & 3 deletions nibabel/nicom/dicomwrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion nibabel/nicom/tests/test_dicomreaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions nibabel/nicom/tests/test_dicomwrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion nibabel/pydicom_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,7 +43,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
Expand Down
1 change: 1 addition & 0 deletions nibabel/tests/test_removalschedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
Expand Down
5 changes: 2 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down