Skip to content

Commit 668f48b

Browse files
committed
Merge pull request #379 from effigies/pydicom1.0
MRG: Prepare for pydicom 1.0 pydicom 1.0 will change the import name from dicom to pydicom, and move dicom.read_file to pydicom.dicomio.read_file. Adjust imports accordingly, and rename dicom to pydicom, when imported directly. Closes #351
2 parents 78abd28 + 83a258a commit 668f48b

File tree

6 files changed

+38
-15
lines changed

6 files changed

+38
-15
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ matrix:
4040
- python: 2.7
4141
env:
4242
- DEPENDS="numpy==1.5.1 pydicom==0.9.7"
43+
# pydicom 1.0 (currently unreleased)
44+
- python: 2.7
45+
env:
46+
- PYDICOM="v1.0"
4347
# Documentation doctests
4448
- python: 2.7
4549
env:
@@ -56,6 +60,8 @@ before_install:
5660
- if [ "${TRAVIS_PYTHON_VERSION:0:1}" == "2" ]; then
5761
if [ "$PYDICOM" == "1" ]; then
5862
pip install pydicom;
63+
elif [ "$PYDICOM" == "v1.0" ]; then
64+
pip install git+https://github.com/darcymason/pydicom.git@43f278444d5cb2e4648135d3edcd430c363c6975;
5965
fi
6066
fi
6167
- if [ "${COVERAGE}" == "1" ]; then

nibabel/nicom/dicomwrappers.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,13 @@ def wrapper_from_file(file_like, *args, **kwargs):
4949
dcm_w : ``dicomwrappers.Wrapper`` or subclass
5050
DICOM wrapper corresponding to DICOM data type
5151
"""
52-
import dicom
52+
try:
53+
from dicom import read_file
54+
except ImportError:
55+
from pydicom.dicomio import read_file
5356

5457
with ImageOpener(file_like) as fobj:
55-
dcm_data = dicom.read_file(fobj, *args, **kwargs)
58+
dcm_data = read_file(fobj, *args, **kwargs)
5659
return wrapper_from_data(dcm_data)
5760

5861

nibabel/nicom/tests/test_csareader.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ def test_csa_header_read():
3131
assert_true(csa.is_mosaic(hdr))
3232
# Get a shallow copy of the data, lacking the CSA marker
3333
# Need to do it this way because del appears broken in pydicom 0.9.7
34-
from dicom.dataset import Dataset
34+
try:
35+
from dicom.dataset import Dataset
36+
except ImportError:
37+
from pydicom.dataset import Dataset
3538
data2 = Dataset()
3639
for element in DATA:
3740
if (element.tag.group, element.tag.elem) != (0x29, 0x10):

nibabel/nicom/tests/test_dicomreaders.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ def test_passing_kwds():
4040
# Check that we correctly pass keywords to dicom
4141
dwi_glob = 'siemens_dwi_*.dcm.gz'
4242
csa_glob = 'csa*.bin'
43-
import dicom
43+
try:
44+
from dicom.filereader import InvalidDicomError
45+
except ImportError:
46+
from pydicom.filereader import InvalidDicomError
4447
for func in (didr.read_mosaic_dwi_dir, didr.read_mosaic_dir):
4548
data, aff, bs, gs = func(IO_DATA_PATH, dwi_glob)
4649
# This should not raise an error
@@ -49,14 +52,14 @@ def test_passing_kwds():
4952
dwi_glob,
5053
dicom_kwargs=dict(force=True))
5154
assert_array_equal(data, data2)
52-
# This should raise an error in dicom.read_file
55+
# This should raise an error in pydicom.dicomio.read_file
5356
assert_raises(TypeError,
5457
func,
5558
IO_DATA_PATH,
5659
dwi_glob,
5760
dicom_kwargs=dict(not_a_parameter=True))
5861
# These are invalid dicoms, so will raise an error unless force=True
59-
assert_raises(dicom.filereader.InvalidDicomError,
62+
assert_raises(InvalidDicomError,
6063
func,
6164
IO_DATA_PATH,
6265
csa_glob)

nibabel/nicom/tests/test_dicomwrappers.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@
99

1010
import numpy as np
1111

12+
have_dicom = True
1213
try:
13-
import dicom
14+
import dicom as pydicom
15+
read_file = pydicom.read_file
1416
except ImportError:
15-
have_dicom = False
16-
else:
17-
have_dicom = True
17+
try:
18+
import pydicom
19+
except ImportError:
20+
have_dicom = False
21+
else:
22+
from pydicom.dicomio import read_file
1823
dicom_test = np.testing.dec.skipif(not have_dicom,
1924
'could not import pydicom')
2025

@@ -32,8 +37,8 @@
3237
DATA_FILE = pjoin(IO_DATA_PATH, 'siemens_dwi_1000.dcm.gz')
3338
DATA_FILE_PHILIPS = pjoin(IO_DATA_PATH, 'philips_mprage.dcm.gz')
3439
if have_dicom:
35-
DATA = dicom.read_file(gzip.open(DATA_FILE))
36-
DATA_PHILIPS = dicom.read_file(gzip.open(DATA_FILE_PHILIPS))
40+
DATA = read_file(gzip.open(DATA_FILE))
41+
DATA_PHILIPS = read_file(gzip.open(DATA_FILE_PHILIPS))
3742
else:
3843
DATA = None
3944
DATA_PHILIPS = None
@@ -166,7 +171,7 @@ def test_wrapper_from_data():
166171

167172
@dicom_test
168173
def test_wrapper_args_kwds():
169-
# Test we can pass args, kwargs to dicom.read_file
174+
# Test we can pass args, kwargs to read_file
170175
dcm = didw.wrapper_from_file(DATA_FILE)
171176
data = dcm.get_data()
172177
# Passing in non-default arg for defer_size
@@ -177,7 +182,7 @@ def test_wrapper_args_kwds():
177182
assert_array_equal(data, dcm2.get_data())
178183
# Trying to read non-dicom file raises pydicom error, usually
179184
csa_fname = pjoin(IO_DATA_PATH, 'csa2_b0.bin')
180-
assert_raises(dicom.filereader.InvalidDicomError,
185+
assert_raises(pydicom.filereader.InvalidDicomError,
181186
didw.wrapper_from_file,
182187
csa_fname)
183188
# We can force the read, in which case rubbish returns

nibabel/nicom/tests/test_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ def test_find_private_section_real():
2828
assert_equal(find_private_section(DATA_PHILIPS, 0x29, 'SIEMENS CSA HEADER'),
2929
None)
3030
# Make fake datasets
31-
from dicom.dataset import Dataset
31+
try:
32+
from dicom.dataset import Dataset
33+
except ImportError:
34+
from pydicom.dataset import Dataset
3235
ds = Dataset({})
3336
ds.add_new((0x11, 0x10), 'LO', b'some section')
3437
assert_equal(find_private_section(ds, 0x11, 'some section'), 0x1000)

0 commit comments

Comments
 (0)