diff --git a/nibabel/__init__.py b/nibabel/__init__.py index 3e57643fc1..ff8911a8c2 100644 --- a/nibabel/__init__.py +++ b/nibabel/__init__.py @@ -78,9 +78,6 @@ def teardown_package(): from .minc2 import Minc2Image from .cifti2 import Cifti2Header, Cifti2Image from .gifti import GiftiImage -# Deprecated backwards compatiblity for MINC1 -from .deprecated import ModuleProxy as _ModuleProxy -minc = _ModuleProxy('nibabel.minc') from .minc1 import MincImage from .freesurfer import MGHImage from .funcs import (squeeze_image, concat_images, four_to_three, @@ -89,6 +86,7 @@ def teardown_package(): flip_axis, OrientationError, apply_orientation, aff2axcodes) from .imageclasses import class_map, ext_map, all_image_classes +from .deprecated import ModuleProxy as _ModuleProxy trackvis = _ModuleProxy('nibabel.trackvis') from . import mriutils from . import streamlines diff --git a/nibabel/analyze.py b/nibabel/analyze.py index dc352505c6..476f26c3a7 100644 --- a/nibabel/analyze.py +++ b/nibabel/analyze.py @@ -939,7 +939,7 @@ def from_file_map(klass, file_map, mmap=True, keep_file_open=None): .. deprecated:: 2.4.1 ``keep_file_open='auto'`` is redundant with `False` and has - been deprecated. It will raise an error in nibabel 3.0. + been deprecated. It raises an error as of nibabel 3.0. Parameters ---------- diff --git a/nibabel/arrayproxy.py b/nibabel/arrayproxy.py index c4189e61e8..b508e651bd 100644 --- a/nibabel/arrayproxy.py +++ b/nibabel/arrayproxy.py @@ -27,7 +27,6 @@ """ from contextlib import contextmanager from threading import RLock -import warnings import numpy as np @@ -48,15 +47,13 @@ If this flag is set to ``True``, a single file handle is created and used. If ``False``, a new file handle is created every time the image is accessed. -If this flag is set to ``'auto'``, a ``DeprecationWarning`` will be raised, which -will become a ``ValueError`` in nibabel 3.0.0. If this is set to any other value, attempts to create an ``ArrayProxy`` without specifying the ``keep_file_open`` flag will result in a ``ValueError`` being raised. .. warning:: Setting this flag to a value of ``'auto'`` became deprecated - behaviour in version 2.4.1. Support for ``'auto'`` will be removed + behaviour in version 2.4.1. Support for ``'auto'`` was removed in version 3.0.0. """ KEEP_FILE_OPEN_DEFAULT = False @@ -102,7 +99,7 @@ def __init__(self, file_like, spec, mmap=True, keep_file_open=None): .. deprecated:: 2.4.1 ``keep_file_open='auto'`` is redundant with `False` and has - been deprecated. It will raise an error in nibabel 3.0. + been deprecated. It raises an error as of nibabel 3.0. Parameters ---------- @@ -239,14 +236,14 @@ def _should_keep_file_open(self, file_like, keep_file_open): .. deprecated:: 2.4.1 ``keep_file_open='auto'`` is redundant with `False` and has - been deprecated. It will be removed in nibabel 3.0. + been deprecated. It raises an error as of nibabel 3.0. Parameters ---------- file_like : object File-like object or filename, as passed to ``__init__``. - keep_file_open : { 'auto', True, False } + keep_file_open : { True, False } Flag as passed to ``__init__``. Returns @@ -259,23 +256,17 @@ def _should_keep_file_open(self, file_like, keep_file_open): """ if keep_file_open is None: keep_file_open = KEEP_FILE_OPEN_DEFAULT - if keep_file_open == 'auto': - warnings.warn("Setting nibabel.arrayproxy.KEEP_FILE_OPEN_DEFAULT to 'auto' is " - "deprecated and will become an error in v3.0.", DeprecationWarning) - if keep_file_open == 'auto': - warnings.warn("A value of 'auto' for keep_file_open is deprecated and will become an " - "error in v3.0. You probably want False.", DeprecationWarning) + if keep_file_open not in (True, False): + raise ValueError("nibabel.arrayproxy.KEEP_FILE_OPEN_DEFAULT must be boolean. " + "Found: {}".format(keep_file_open)) elif keep_file_open not in (True, False): - raise ValueError('keep_file_open should be one of {None, True, False}') + raise ValueError('keep_file_open must be one of {None, True, False}') # file_like is a handle - keep_file_open is irrelevant if hasattr(file_like, 'read') and hasattr(file_like, 'seek'): return False, False # if the file is a gzip file, and we have_indexed_gzip, have_igzip = openers.HAVE_INDEXED_GZIP and file_like.endswith('.gz') - # XXX Remove in v3.0 - if keep_file_open == 'auto': - return have_igzip, have_igzip persist_opener = keep_file_open or have_igzip return keep_file_open, persist_opener diff --git a/nibabel/brikhead.py b/nibabel/brikhead.py index 7ef1386872..41bfc54c4d 100644 --- a/nibabel/brikhead.py +++ b/nibabel/brikhead.py @@ -227,7 +227,7 @@ def __init__(self, file_like, header, mmap=True, keep_file_open=None): .. deprecated:: 2.4.1 ``keep_file_open='auto'`` is redundant with `False` and has - been deprecated. It will raise an error in nibabel 3.0. + been deprecated. It raises an error as of nibabel 3.0. Parameters ---------- @@ -511,7 +511,7 @@ def from_file_map(klass, file_map, mmap=True, keep_file_open=None): .. deprecated:: 2.4.1 ``keep_file_open='auto'`` is redundant with `False` and has - been deprecated. It will raise an error in nibabel 3.0. + been deprecated. It raises an error as of nibabel 3.0. Parameters ---------- diff --git a/nibabel/checkwarns.py b/nibabel/checkwarns.py deleted file mode 100644 index a5942427b6..0000000000 --- a/nibabel/checkwarns.py +++ /dev/null @@ -1,31 +0,0 @@ -# emacs: -*- mode: python-mode; py-indent-offset: 4; indent-tabs-mode: nil -*- -# vi: set ft=python sts=4 ts=4 sw=4 et: -### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -# -# See COPYING file distributed along with the NiBabel package for the -# copyright and license terms. -# -### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -''' Contexts for *with* statement allowing checks for warnings -''' - -import warnings - -from .testing import (error_warnings, suppress_warnings) -from .deprecated import deprecate_with_version - - -warnings.warn('The checkwarns module is deprecated and will be removed ' - 'in nibabel v3.0', DeprecationWarning) - - -@deprecate_with_version('ErrorWarnings is deprecated; use nibabel.testing.error_warnings.', - since='2.1.0', until='3.0.0') -class ErrorWarnings(error_warnings): - pass - - -@deprecate_with_version('IgnoreWarnings is deprecated; use nibabel.testing.suppress_warnings.', - since='2.1.0', until='3.0.0') -class IgnoreWarnings(suppress_warnings): - pass diff --git a/nibabel/dataobj_images.py b/nibabel/dataobj_images.py index 4b4d1b55d8..a761d62b77 100644 --- a/nibabel/dataobj_images.py +++ b/nibabel/dataobj_images.py @@ -421,7 +421,7 @@ def from_file_map(klass, file_map, mmap=True, keep_file_open=None): .. deprecated:: 2.4.1 ``keep_file_open='auto'`` is redundant with `False` and has - been deprecated. It will raise an error in nibabel 3.0. + been deprecated. It raises an error as of nibabel 3.0. Parameters ---------- @@ -459,7 +459,7 @@ def from_filename(klass, filename, mmap=True, keep_file_open=None): .. deprecated:: 2.4.1 ``keep_file_open='auto'`` is redundant with `False` and has - been deprecated. It will raise an error in nibabel 3.0. + been deprecated. It raises an error as of nibabel 3.0. Parameters ---------- diff --git a/nibabel/deprecated.py b/nibabel/deprecated.py index 715ee7f60d..1a0f85330d 100644 --- a/nibabel/deprecated.py +++ b/nibabel/deprecated.py @@ -20,10 +20,10 @@ class ModuleProxy(object): :: arr = np.arange(24).reshape((2, 3, 4)) - minc = ModuleProxy('nibabel.minc') - minc_image = minc.Minc1Image(arr, np.eye(4)) + nifti1 = ModuleProxy('nibabel.nifti1') + nifti1_image = nifti1.Nifti1Image(arr, np.eye(4)) - So, the ``minc`` object is a proxy that will import the required module + So, the ``nifti1`` object is a proxy that will import the required module when you do attribute access and return the attributes of the imported module. """ diff --git a/nibabel/freesurfer/mghformat.py b/nibabel/freesurfer/mghformat.py index 6eb0f156e9..75c6de9781 100644 --- a/nibabel/freesurfer/mghformat.py +++ b/nibabel/freesurfer/mghformat.py @@ -543,7 +543,7 @@ def from_file_map(klass, file_map, mmap=True, keep_file_open=None): .. deprecated:: 2.4.1 ``keep_file_open='auto'`` is redundant with `False` and has - been deprecated. It will raise an error in nibabel 3.0. + been deprecated. It raises an error as of nibabel 3.0. Parameters ---------- diff --git a/nibabel/minc.py b/nibabel/minc.py deleted file mode 100644 index 09523bdc36..0000000000 --- a/nibabel/minc.py +++ /dev/null @@ -1,10 +0,0 @@ -""" Deprecated MINC1 module """ - -import warnings - -warnings.warn("We will remove this module from nibabel 3.0; " - "Please use the 'minc1' module instead", - DeprecationWarning, - stacklevel=2) - -from .minc1 import * # noqa diff --git a/nibabel/spm99analyze.py b/nibabel/spm99analyze.py index d420bb0c2e..e7aaa77048 100644 --- a/nibabel/spm99analyze.py +++ b/nibabel/spm99analyze.py @@ -250,7 +250,7 @@ def from_file_map(klass, file_map, mmap=True, keep_file_open=None): .. deprecated:: 2.4.1 ``keep_file_open='auto'`` is redundant with `False` and has - been deprecated. It will raise an error in nibabel 3.0. + been deprecated. It raises an error as of nibabel 3.0. Parameters ---------- diff --git a/nibabel/tests/test_arrayproxy.py b/nibabel/tests/test_arrayproxy.py index b1cc081b6d..af7d5b73e6 100644 --- a/nibabel/tests/test_arrayproxy.py +++ b/nibabel/tests/test_arrayproxy.py @@ -372,8 +372,6 @@ def test_keep_file_open_true_false_invalid(): # False | True | True | True # True | False | True | n/a # True | True | True | False - # 'auto' | False | False | n/a - # 'auto' | True | True | False # # Each test tuple contains: # - file type - gzipped ('gz') or not ('bin'), or an open file handle @@ -388,26 +386,18 @@ def test_keep_file_open_true_false_invalid(): ('open', False, True, False, False), ('open', True, False, False, False), ('open', True, True, False, False), - ('open', 'auto', False, False, False), - ('open', 'auto', True, False, False), # non-gzip file - have_igzip is irrelevant, decision should be made # solely from kfo flag ('bin', False, False, False, False), ('bin', False, True, False, False), ('bin', True, False, True, True), ('bin', True, True, True, True), - ('bin', 'auto', False, False, False), - ('bin', 'auto', True, False, False), - # gzip file. If igzip is present, we persist the ImageOpener. If kfo - # is 'auto': - # - if igzip is present, kfo -> True - # - otherwise, kfo -> False + # gzip file. If igzip is present, we persist the ImageOpener. ('gz', False, False, False, False), ('gz', False, True, True, False), ('gz', True, False, True, True), ('gz', True, True, True, True), - ('gz', 'auto', False, False, False), - ('gz', 'auto', True, True, True)] + ] dtype = np.float32 data = np.arange(1000, dtype=dtype).reshape((10, 10, 10)) @@ -477,12 +467,14 @@ def test_keep_file_open_true_false_invalid(): fname = 'testdata' with open(fname, 'wb') as fobj: fobj.write(data.tostring(order='F')) - with assert_raises(ValueError): - ArrayProxy(fname, ((10, 10, 10), dtype), keep_file_open=55) - with assert_raises(ValueError): - ArrayProxy(fname, ((10, 10, 10), dtype), keep_file_open='autob') - with assert_raises(ValueError): - ArrayProxy(fname, ((10, 10, 10), dtype), keep_file_open='cauto') + + for invalid_kfo in (55, 'auto', 'cauto'): + with assert_raises(ValueError): + ArrayProxy(fname, ((10, 10, 10), dtype), + keep_file_open=invalid_kfo) + with patch_keep_file_open_default(invalid_kfo): + with assert_raises(ValueError): + ArrayProxy(fname, ((10, 10, 10), dtype)) def test_pickle_lock(): diff --git a/nibabel/tests/test_checkwarns.py b/nibabel/tests/test_checkwarns.py deleted file mode 100644 index b1e6483273..0000000000 --- a/nibabel/tests/test_checkwarns.py +++ /dev/null @@ -1,11 +0,0 @@ -""" Tests for warnings context managers -""" -from ..testing import assert_equal, assert_warns, suppress_warnings - - -def test_ignore_and_error_warnings(): - with suppress_warnings(): - from .. import checkwarns - - assert_warns(DeprecationWarning, checkwarns.IgnoreWarnings) - assert_warns(DeprecationWarning, checkwarns.ErrorWarnings) diff --git a/nibabel/tests/test_minc1.py b/nibabel/tests/test_minc1.py index a4d42fdc36..c5d92119ae 100644 --- a/nibabel/tests/test_minc1.py +++ b/nibabel/tests/test_minc1.py @@ -104,30 +104,10 @@ def test_old_namespace(): # Check warnings raised arr = np.arange(24).reshape((2, 3, 4)) aff = np.diag([2, 3, 4, 1]) - with clear_and_catch_warnings() as warns: - warnings.simplefilter('always', DeprecationWarning) - # Top level import. - # This import does not trigger an import of the minc.py module, because - # it's the proxy object. - from .. import minc - assert_equal(warns, []) - # If there was a previous import it will be module, otherwise it will be - # a proxy - previous_import = isinstance(minc, types.ModuleType) - if not previous_import: - assert_true(isinstance(minc, ModuleProxy)) - old_minc1image = minc.Minc1Image # just to check it works - # There may or may not be a warning raised on accessing the proxy, - # depending on whether the minc.py module is already imported in this - # test run. - if not previous_import: - assert_equal(warns.pop(0).category, DeprecationWarning) with clear_and_catch_warnings() as warns: from .. import Minc1Image, MincImage assert_equal(warns, []) - # The import from old module is the same as that from new - assert_true(old_minc1image is Minc1Image) # But the old named import, imported from new, is not the same assert_false(Minc1Image is MincImage) assert_equal(warns, [])