Skip to content
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: 1 addition & 3 deletions nibabel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion nibabel/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand Down
25 changes: 8 additions & 17 deletions nibabel/arrayproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"""
from contextlib import contextmanager
from threading import RLock
import warnings

import numpy as np

Expand All @@ -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
Expand Down Expand Up @@ -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
----------
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions nibabel/brikhead.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand Down Expand Up @@ -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
----------
Expand Down
31 changes: 0 additions & 31 deletions nibabel/checkwarns.py

This file was deleted.

4 changes: 2 additions & 2 deletions nibabel/dataobj_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand Down Expand Up @@ -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
----------
Expand Down
6 changes: 3 additions & 3 deletions nibabel/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
2 changes: 1 addition & 1 deletion nibabel/freesurfer/mghformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand Down
10 changes: 0 additions & 10 deletions nibabel/minc.py

This file was deleted.

2 changes: 1 addition & 1 deletion nibabel/spm99analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand Down
28 changes: 10 additions & 18 deletions nibabel/tests/test_arrayproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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():
Expand Down
11 changes: 0 additions & 11 deletions nibabel/tests/test_checkwarns.py

This file was deleted.

20 changes: 0 additions & 20 deletions nibabel/tests/test_minc1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, [])
Expand Down