Skip to content

MNT: 5.0.0.dev0 #1141

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

Merged
merged 17 commits into from
Dec 16, 2022
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
5 changes: 2 additions & 3 deletions nibabel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@
from .freesurfer import MGHImage
from .funcs import (squeeze_image, concat_images, four_to_three,
as_closest_canonical)
from .orientations import (io_orientation, orientation_affine,
flip_axis, OrientationError,
from .orientations import (io_orientation, flip_axis, OrientationError,
apply_orientation, aff2axcodes)
from .imageclasses import class_map, ext_map, all_image_classes
from .imageclasses import all_image_classes
from . import mriutils
from . import streamlines
from . import viewers
Expand Down
29 changes: 3 additions & 26 deletions nibabel/arraywriters.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def __init__(self, array, out_dtype=None)
from .casting import (int_to_float, as_int, int_abs, type_info, floor_exact,
best_float, shared_range)
from .volumeutils import finite_range, array_to_file
from .deprecator import ExpiredDeprecationError


class WriterError(Exception):
Expand Down Expand Up @@ -185,38 +184,22 @@ def finite_range(self):
self._has_nan = has_nan
return self._finite_range

def _check_nan2zero(self, nan2zero):
if nan2zero is None:
return
if nan2zero != self._nan2zero:
raise WriterError('Deprecated `nan2zero` argument to `to_fileobj` '
'must be same as class value set in __init__')
raise ExpiredDeprecationError(
'Please remove `nan2zero` from call to `to_fileobj` '
'and use in instance __init__ instead.\n'
'* deprecated in version: 2.0\n'
'* Raises ExpiredDeprecationError as of version: 4.0\n'
)

def _needs_nan2zero(self):
""" True if nan2zero check needed for writing array """
return (self._nan2zero and
self._array.dtype.kind in 'fc' and
self.out_dtype.kind in 'iu' and
self.has_nan)

def to_fileobj(self, fileobj, order='F', nan2zero=None):
def to_fileobj(self, fileobj, order='F'):
""" Write array into `fileobj`

Parameters
----------
fileobj : file-like object
order : {'F', 'C'}
order (Fortran or C) to which to write array
nan2zero : {None, True, False}, optional, deprecated
Deprecated version of argument to __init__ with same name
"""
self._check_nan2zero(nan2zero)
array_to_file(self._array,
fileobj,
self._out_dtype,
Expand Down Expand Up @@ -362,18 +345,15 @@ def _writing_range(self):
return mn, mx
return None, None

def to_fileobj(self, fileobj, order='F', nan2zero=None):
def to_fileobj(self, fileobj, order='F'):
""" Write array into `fileobj`

Parameters
----------
fileobj : file-like object
order : {'F', 'C'}
order (Fortran or C) to which to write array
nan2zero : {None, True, False}, optional, deprecated
Deprecated version of argument to __init__ with same name
"""
self._check_nan2zero(nan2zero)
mn, mx = self._writing_range()
array_to_file(self._array,
fileobj,
Expand Down Expand Up @@ -536,18 +516,15 @@ def _set_inter(self, val):
self._inter = np.squeeze(self.scaler_dtype.type(val))
inter = property(_get_inter, _set_inter, None, 'get/set inter')

def to_fileobj(self, fileobj, order='F', nan2zero=None):
def to_fileobj(self, fileobj, order='F'):
""" Write array into `fileobj`

Parameters
----------
fileobj : file-like object
order : {'F', 'C'}
order (Fortran or C) to which to write array
nan2zero : {None, True, False}, optional, deprecated
Deprecated version of argument to __init__ with same name
"""
self._check_nan2zero(nan2zero)
mn, mx = self._writing_range()
array_to_file(self._array,
fileobj,
Expand Down
6 changes: 0 additions & 6 deletions nibabel/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import pytest

# Pre-load deprecated modules to avoid cluttering warnings
with pytest.deprecated_call():
import nibabel.keywordonly
with pytest.warns(FutureWarning):
import nibabel.py3k

# Ignore warning requesting help with nicom
with pytest.warns(UserWarning):
import nibabel.nicom
7 changes: 0 additions & 7 deletions nibabel/dataobj_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ def __init__(self, dataobj, header=None, extra=None, file_map=None):
def dataobj(self):
return self._dataobj

@property
@deprecate_with_version('_data attribute not part of public API. '
'please use "dataobj" property instead.',
'2.0', '4.0')
def _data(self):
return self._dataobj

@deprecate_with_version('get_data() is deprecated in favor of get_fdata(),'
' which has a more predictable return type. To '
'obtain get_data() behavior going forward, use '
Expand Down
9 changes: 0 additions & 9 deletions nibabel/ecat.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
from .arraywriters import make_array_writer
from .wrapstruct import WrapStruct
from .fileslice import canonical_slicers, predict_shape, slice2outax
from .deprecated import deprecate_with_version

BLOCK_SIZE = 512

Expand Down Expand Up @@ -863,14 +862,6 @@ def get_subheaders(self):
"""get access to subheaders"""
return self._subheader

@classmethod
@deprecate_with_version('from_filespec class method is deprecated.\n'
'Please use the ``from_file_map`` class method '
'instead.',
'2.1', '4.0')
def from_filespec(klass, filespec):
return klass.from_filename(filespec)

@staticmethod
def _get_fileholders(file_map):
""" returns files specific to header and image of the image
Expand Down
11 changes: 0 additions & 11 deletions nibabel/filebasedimages.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from .filename_parser import (types_filenames, TypesFilenamesError,
splitext_addext)
from .openers import ImageOpener
from .deprecated import deprecate_with_version


class ImageFileError(Exception):
Expand Down Expand Up @@ -79,7 +78,6 @@ class FileBasedImage:

methods:

* get_header() (deprecated, use header property instead)
* to_filename(fname) - writes data to filename(s) derived from
``fname``, where the derivation may differ between formats.
* to_file_map() - save image to files with which the image is already
Expand Down Expand Up @@ -208,15 +206,6 @@ def __getitem__(self, key):
"""
raise TypeError("Cannot slice image objects.")

@deprecate_with_version('get_header method is deprecated.\n'
'Please use the ``img.header`` property '
'instead.',
'2.1', '4.0')
def get_header(self):
""" Get header from image
"""
return self.header

def get_filename(self):
""" Fetch the image filename

Expand Down
40 changes: 0 additions & 40 deletions nibabel/freesurfer/mghformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from ..openers import ImageOpener
from ..batteryrunners import BatteryRunner, Report
from ..wrapstruct import LabeledWrapStruct
from ..deprecated import deprecate_with_version

# mgh header
# See https://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/MghFormat
Expand Down Expand Up @@ -462,45 +461,6 @@ def diagnose_binaryblock(klass, binaryblock, endianness=None):
return '\n'.join([report.message
for report in reports if report.message])

class _HeaderData:
""" Provide interface to deprecated MGHHeader fields"""
def __init__(self, structarr):
self._structarr = structarr

def __getitem__(self, item):
sa = self._structarr
if item == 'mrparams':
return np.hstack((sa['tr'], sa['flip_angle'], sa['te'], sa['ti']))
return sa[item]

def __setitem__(self, item, val):
sa = self._structarr
if item == 'mrparams':
sa['tr'], sa['flip_angle'], sa['te'], sa['ti'] = val
else:
sa[item] = val

@property
@deprecate_with_version('_header_data is deprecated.\n'
'Please use the _structarr interface instead.\n'
'Note also that some fields have changed name and '
'shape.',
'2.3', '4.0')
def _header_data(self):
""" Deprecated field-access interface """
return self._HeaderData(self._structarr)

def __getitem__(self, item):
if item == 'mrparams':
return self._header_data[item]
return super(MGHHeader, self).__getitem__(item)

def __setitem__(self, item, value):
if item == 'mrparams':
self._header_data[item] = value
else:
super(MGHHeader, self).__setitem__(item, value)


class MGHImage(SpatialImage, SerializableImage):
""" Class for MGH format image
Expand Down
15 changes: 0 additions & 15 deletions nibabel/freesurfer/tests/test_mghformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from ...volumeutils import sys_is_le
from ...wrapstruct import WrapStructError
from ... import imageglobals
from ...deprecator import ExpiredDeprecationError


import pytest
Expand Down Expand Up @@ -340,20 +339,6 @@ def test_mghheader_default_structarr():
MGHHeader.default_structarr(endianness=endianness)


def test_deprecated_fields():
hdr = MGHHeader()
hdr_data = MGHHeader._HeaderData(hdr.structarr)

# mrparams is the only deprecated field at the moment
# Accessing hdr_data is equivalent to accessing hdr, so double all checks,
# but expect success on hdr_data['mrparams']
with pytest.raises(ExpiredDeprecationError):
hdr['mrparams']
with pytest.raises(ExpiredDeprecationError):
hdr['mrparams'] = [1, 2, 3, 4]
assert_array_equal(hdr_data['mrparams'], 0)


class TestMGHImage(tsi.TestSpatialImage, tsi.MmapImageMixin):
""" Apply general image tests to MGHImage
"""
Expand Down
1 change: 0 additions & 1 deletion nibabel/gifti/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@
gifti
"""

from .giftiio import read, write
from .gifti import (GiftiMetaData, GiftiNVPairs, GiftiLabelTable, GiftiLabel,
GiftiCoordSystem, GiftiDataArray, GiftiImage)
Loading