Skip to content

Commit 54951c0

Browse files
authored
Merge pull request #852 from effigies/mnt/deprecations
MNT: Scheduled removals for 3.0
2 parents d8cf1a9 + 64f9961 commit 54951c0

13 files changed

+29
-120
lines changed

nibabel/__init__.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ def teardown_package():
7878
from .minc2 import Minc2Image
7979
from .cifti2 import Cifti2Header, Cifti2Image
8080
from .gifti import GiftiImage
81-
# Deprecated backwards compatiblity for MINC1
82-
from .deprecated import ModuleProxy as _ModuleProxy
83-
minc = _ModuleProxy('nibabel.minc')
8481
from .minc1 import MincImage
8582
from .freesurfer import MGHImage
8683
from .funcs import (squeeze_image, concat_images, four_to_three,
@@ -89,6 +86,7 @@ def teardown_package():
8986
flip_axis, OrientationError,
9087
apply_orientation, aff2axcodes)
9188
from .imageclasses import class_map, ext_map, all_image_classes
89+
from .deprecated import ModuleProxy as _ModuleProxy
9290
trackvis = _ModuleProxy('nibabel.trackvis')
9391
from . import mriutils
9492
from . import streamlines

nibabel/analyze.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
939939
940940
.. deprecated:: 2.4.1
941941
``keep_file_open='auto'`` is redundant with `False` and has
942-
been deprecated. It will raise an error in nibabel 3.0.
942+
been deprecated. It raises an error as of nibabel 3.0.
943943
944944
Parameters
945945
----------

nibabel/arrayproxy.py

+8-17
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"""
2828
from contextlib import contextmanager
2929
from threading import RLock
30-
import warnings
3130

3231
import numpy as np
3332

@@ -48,15 +47,13 @@
4847
4948
If this flag is set to ``True``, a single file handle is created and used. If
5049
``False``, a new file handle is created every time the image is accessed.
51-
If this flag is set to ``'auto'``, a ``DeprecationWarning`` will be raised, which
52-
will become a ``ValueError`` in nibabel 3.0.0.
5350
5451
If this is set to any other value, attempts to create an ``ArrayProxy`` without
5552
specifying the ``keep_file_open`` flag will result in a ``ValueError`` being
5653
raised.
5754
5855
.. warning:: Setting this flag to a value of ``'auto'`` became deprecated
59-
behaviour in version 2.4.1. Support for ``'auto'`` will be removed
56+
behaviour in version 2.4.1. Support for ``'auto'`` was removed
6057
in version 3.0.0.
6158
"""
6259
KEEP_FILE_OPEN_DEFAULT = False
@@ -102,7 +99,7 @@ def __init__(self, file_like, spec, mmap=True, keep_file_open=None):
10299
103100
.. deprecated:: 2.4.1
104101
``keep_file_open='auto'`` is redundant with `False` and has
105-
been deprecated. It will raise an error in nibabel 3.0.
102+
been deprecated. It raises an error as of nibabel 3.0.
106103
107104
Parameters
108105
----------
@@ -239,14 +236,14 @@ def _should_keep_file_open(self, file_like, keep_file_open):
239236
240237
.. deprecated:: 2.4.1
241238
``keep_file_open='auto'`` is redundant with `False` and has
242-
been deprecated. It will be removed in nibabel 3.0.
239+
been deprecated. It raises an error as of nibabel 3.0.
243240
244241
Parameters
245242
----------
246243
247244
file_like : object
248245
File-like object or filename, as passed to ``__init__``.
249-
keep_file_open : { 'auto', True, False }
246+
keep_file_open : { True, False }
250247
Flag as passed to ``__init__``.
251248
252249
Returns
@@ -259,23 +256,17 @@ def _should_keep_file_open(self, file_like, keep_file_open):
259256
"""
260257
if keep_file_open is None:
261258
keep_file_open = KEEP_FILE_OPEN_DEFAULT
262-
if keep_file_open == 'auto':
263-
warnings.warn("Setting nibabel.arrayproxy.KEEP_FILE_OPEN_DEFAULT to 'auto' is "
264-
"deprecated and will become an error in v3.0.", DeprecationWarning)
265-
if keep_file_open == 'auto':
266-
warnings.warn("A value of 'auto' for keep_file_open is deprecated and will become an "
267-
"error in v3.0. You probably want False.", DeprecationWarning)
259+
if keep_file_open not in (True, False):
260+
raise ValueError("nibabel.arrayproxy.KEEP_FILE_OPEN_DEFAULT must be boolean. "
261+
"Found: {}".format(keep_file_open))
268262
elif keep_file_open not in (True, False):
269-
raise ValueError('keep_file_open should be one of {None, True, False}')
263+
raise ValueError('keep_file_open must be one of {None, True, False}')
270264

271265
# file_like is a handle - keep_file_open is irrelevant
272266
if hasattr(file_like, 'read') and hasattr(file_like, 'seek'):
273267
return False, False
274268
# if the file is a gzip file, and we have_indexed_gzip,
275269
have_igzip = openers.HAVE_INDEXED_GZIP and file_like.endswith('.gz')
276-
# XXX Remove in v3.0
277-
if keep_file_open == 'auto':
278-
return have_igzip, have_igzip
279270

280271
persist_opener = keep_file_open or have_igzip
281272
return keep_file_open, persist_opener

nibabel/brikhead.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def __init__(self, file_like, header, mmap=True, keep_file_open=None):
227227
228228
.. deprecated:: 2.4.1
229229
``keep_file_open='auto'`` is redundant with `False` and has
230-
been deprecated. It will raise an error in nibabel 3.0.
230+
been deprecated. It raises an error as of nibabel 3.0.
231231
232232
Parameters
233233
----------
@@ -511,7 +511,7 @@ def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
511511
512512
.. deprecated:: 2.4.1
513513
``keep_file_open='auto'`` is redundant with `False` and has
514-
been deprecated. It will raise an error in nibabel 3.0.
514+
been deprecated. It raises an error as of nibabel 3.0.
515515
516516
Parameters
517517
----------

nibabel/checkwarns.py

-31
This file was deleted.

nibabel/dataobj_images.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
421421
422422
.. deprecated:: 2.4.1
423423
``keep_file_open='auto'`` is redundant with `False` and has
424-
been deprecated. It will raise an error in nibabel 3.0.
424+
been deprecated. It raises an error as of nibabel 3.0.
425425
426426
Parameters
427427
----------
@@ -459,7 +459,7 @@ def from_filename(klass, filename, mmap=True, keep_file_open=None):
459459
460460
.. deprecated:: 2.4.1
461461
``keep_file_open='auto'`` is redundant with `False` and has
462-
been deprecated. It will raise an error in nibabel 3.0.
462+
been deprecated. It raises an error as of nibabel 3.0.
463463
464464
Parameters
465465
----------

nibabel/deprecated.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ class ModuleProxy(object):
2020
2121
::
2222
arr = np.arange(24).reshape((2, 3, 4))
23-
minc = ModuleProxy('nibabel.minc')
24-
minc_image = minc.Minc1Image(arr, np.eye(4))
23+
nifti1 = ModuleProxy('nibabel.nifti1')
24+
nifti1_image = nifti1.Nifti1Image(arr, np.eye(4))
2525
26-
So, the ``minc`` object is a proxy that will import the required module
26+
So, the ``nifti1`` object is a proxy that will import the required module
2727
when you do attribute access and return the attributes of the imported
2828
module.
2929
"""

nibabel/freesurfer/mghformat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
543543
544544
.. deprecated:: 2.4.1
545545
``keep_file_open='auto'`` is redundant with `False` and has
546-
been deprecated. It will raise an error in nibabel 3.0.
546+
been deprecated. It raises an error as of nibabel 3.0.
547547
548548
Parameters
549549
----------

nibabel/minc.py

-10
This file was deleted.

nibabel/spm99analyze.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
250250
251251
.. deprecated:: 2.4.1
252252
``keep_file_open='auto'`` is redundant with `False` and has
253-
been deprecated. It will raise an error in nibabel 3.0.
253+
been deprecated. It raises an error as of nibabel 3.0.
254254
255255
Parameters
256256
----------

nibabel/tests/test_arrayproxy.py

+10-18
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,6 @@ def test_keep_file_open_true_false_invalid():
372372
# False | True | True | True
373373
# True | False | True | n/a
374374
# True | True | True | False
375-
# 'auto' | False | False | n/a
376-
# 'auto' | True | True | False
377375
#
378376
# Each test tuple contains:
379377
# - file type - gzipped ('gz') or not ('bin'), or an open file handle
@@ -388,26 +386,18 @@ def test_keep_file_open_true_false_invalid():
388386
('open', False, True, False, False),
389387
('open', True, False, False, False),
390388
('open', True, True, False, False),
391-
('open', 'auto', False, False, False),
392-
('open', 'auto', True, False, False),
393389
# non-gzip file - have_igzip is irrelevant, decision should be made
394390
# solely from kfo flag
395391
('bin', False, False, False, False),
396392
('bin', False, True, False, False),
397393
('bin', True, False, True, True),
398394
('bin', True, True, True, True),
399-
('bin', 'auto', False, False, False),
400-
('bin', 'auto', True, False, False),
401-
# gzip file. If igzip is present, we persist the ImageOpener. If kfo
402-
# is 'auto':
403-
# - if igzip is present, kfo -> True
404-
# - otherwise, kfo -> False
395+
# gzip file. If igzip is present, we persist the ImageOpener.
405396
('gz', False, False, False, False),
406397
('gz', False, True, True, False),
407398
('gz', True, False, True, True),
408399
('gz', True, True, True, True),
409-
('gz', 'auto', False, False, False),
410-
('gz', 'auto', True, True, True)]
400+
]
411401

412402
dtype = np.float32
413403
data = np.arange(1000, dtype=dtype).reshape((10, 10, 10))
@@ -477,12 +467,14 @@ def test_keep_file_open_true_false_invalid():
477467
fname = 'testdata'
478468
with open(fname, 'wb') as fobj:
479469
fobj.write(data.tostring(order='F'))
480-
with assert_raises(ValueError):
481-
ArrayProxy(fname, ((10, 10, 10), dtype), keep_file_open=55)
482-
with assert_raises(ValueError):
483-
ArrayProxy(fname, ((10, 10, 10), dtype), keep_file_open='autob')
484-
with assert_raises(ValueError):
485-
ArrayProxy(fname, ((10, 10, 10), dtype), keep_file_open='cauto')
470+
471+
for invalid_kfo in (55, 'auto', 'cauto'):
472+
with assert_raises(ValueError):
473+
ArrayProxy(fname, ((10, 10, 10), dtype),
474+
keep_file_open=invalid_kfo)
475+
with patch_keep_file_open_default(invalid_kfo):
476+
with assert_raises(ValueError):
477+
ArrayProxy(fname, ((10, 10, 10), dtype))
486478

487479

488480
def test_pickle_lock():

nibabel/tests/test_checkwarns.py

-11
This file was deleted.

nibabel/tests/test_minc1.py

-20
Original file line numberDiff line numberDiff line change
@@ -104,30 +104,10 @@ def test_old_namespace():
104104
# Check warnings raised
105105
arr = np.arange(24).reshape((2, 3, 4))
106106
aff = np.diag([2, 3, 4, 1])
107-
with clear_and_catch_warnings() as warns:
108-
warnings.simplefilter('always', DeprecationWarning)
109-
# Top level import.
110-
# This import does not trigger an import of the minc.py module, because
111-
# it's the proxy object.
112-
from .. import minc
113-
assert_equal(warns, [])
114-
# If there was a previous import it will be module, otherwise it will be
115-
# a proxy
116-
previous_import = isinstance(minc, types.ModuleType)
117-
if not previous_import:
118-
assert_true(isinstance(minc, ModuleProxy))
119-
old_minc1image = minc.Minc1Image # just to check it works
120-
# There may or may not be a warning raised on accessing the proxy,
121-
# depending on whether the minc.py module is already imported in this
122-
# test run.
123-
if not previous_import:
124-
assert_equal(warns.pop(0).category, DeprecationWarning)
125107

126108
with clear_and_catch_warnings() as warns:
127109
from .. import Minc1Image, MincImage
128110
assert_equal(warns, [])
129-
# The import from old module is the same as that from new
130-
assert_true(old_minc1image is Minc1Image)
131111
# But the old named import, imported from new, is not the same
132112
assert_false(Minc1Image is MincImage)
133113
assert_equal(warns, [])

0 commit comments

Comments
 (0)