Skip to content

Commit 225892a

Browse files
committed
Merge branch 'maint/4.0.x'
2 parents a99fe64 + c90b75d commit 225892a

17 files changed

+159
-254
lines changed

Changelog

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,30 @@ Eric Larson (EL), Demian Wassermann, Stephan Gerhard and Ross Markello (RM).
2525

2626
References like "pr/298" refer to github pull request numbers.
2727

28+
4.0.1 (Saturday 18 June 2022)
29+
=============================
30+
31+
Bug-fix release in the 4.0.x series.
32+
33+
Bug fixes
34+
---------
35+
* Finalize 4.0 deprecations, converting tests expecting ``DeprecationWarning`` to
36+
expected ``ExpiredDeprecationError`` (pr/1117) (CM)
37+
38+
Maintenance
39+
-----------
40+
* Suppress new numpy warning on nan-to-int cast (pr/1118) (CM, reviewed by MB)
41+
42+
2843
4.0.0 (Saturday 18 June 2022)
2944
=============================
3045

3146
New feature release in the 4.0.x series.
3247

3348
New features
3449
------------
50+
* ``nib-convert`` CLI tool to make image type and data dtype conversion accessible
51+
via the command line. (pr/1113) (CM, reviewed by Ariel Rokem)
3552
* Add ``'mask'``, ``'compat'`` and ``'smallest'`` dtype aliases to NIfTI images
3653
to allow for dtype specifications that can depend on the contents of the data.
3754
``'mask'`` is a synonym for ``uint8``. ``'compat'`` will find the nearest

nibabel/freesurfer/tests/test_mghformat.py

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from ...volumeutils import sys_is_le
2323
from ...wrapstruct import WrapStructError
2424
from ... import imageglobals
25+
from ...deprecator import ExpiredDeprecationError
2526

2627

2728
import pytest
@@ -344,42 +345,13 @@ def test_deprecated_fields():
344345
hdr_data = MGHHeader._HeaderData(hdr.structarr)
345346

346347
# mrparams is the only deprecated field at the moment
347-
# Accessing hdr_data is equivalent to accessing hdr, so double all checks
348-
with pytest.deprecated_call(match="from version: 2.3"):
349-
assert_array_equal(hdr['mrparams'], 0)
350-
assert_array_equal(hdr_data['mrparams'], 0)
351-
352-
with pytest.deprecated_call(match="from version: 2.3"):
348+
# Accessing hdr_data is equivalent to accessing hdr, so double all checks,
349+
# but expect success on hdr_data['mrparams']
350+
with pytest.raises(ExpiredDeprecationError):
351+
hdr['mrparams']
352+
with pytest.raises(ExpiredDeprecationError):
353353
hdr['mrparams'] = [1, 2, 3, 4]
354-
with pytest.deprecated_call(match="from version: 2.3"):
355-
assert_array_almost_equal(hdr['mrparams'], [1, 2, 3, 4])
356-
assert hdr['tr'] == 1
357-
assert hdr['flip_angle'] == 2
358-
assert hdr['te'] == 3
359-
assert hdr['ti'] == 4
360-
assert hdr['fov'] == 0
361-
assert_array_almost_equal(hdr_data['mrparams'], [1, 2, 3, 4])
362-
assert hdr_data['tr'] == 1
363-
assert hdr_data['flip_angle'] == 2
364-
assert hdr_data['te'] == 3
365-
assert hdr_data['ti'] == 4
366-
assert hdr_data['fov'] == 0
367-
368-
hdr['tr'] = 5
369-
hdr['flip_angle'] = 6
370-
hdr['te'] = 7
371-
hdr['ti'] = 8
372-
with pytest.deprecated_call(match="from version: 2.3"):
373-
assert_array_almost_equal(hdr['mrparams'], [5, 6, 7, 8])
374-
assert_array_almost_equal(hdr_data['mrparams'], [5, 6, 7, 8])
375-
376-
hdr_data['tr'] = 9
377-
hdr_data['flip_angle'] = 10
378-
hdr_data['te'] = 11
379-
hdr_data['ti'] = 12
380-
with pytest.deprecated_call(match="from version: 2.3"):
381-
assert_array_almost_equal(hdr['mrparams'], [9, 10, 11, 12])
382-
assert_array_almost_equal(hdr_data['mrparams'], [9, 10, 11, 12])
354+
assert_array_equal(hdr_data['mrparams'], 0)
383355

384356

385357
class TestMGHImage(tsi.TestSpatialImage, tsi.MmapImageMixin):

nibabel/gifti/tests/test_gifti.py

Lines changed: 19 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
from ..gifti import data_tag
1616
from ...nifti1 import data_type_codes
1717
from ...fileholders import FileHolder
18+
from ...deprecator import ExpiredDeprecationError
1819

1920
from numpy.testing import assert_array_almost_equal, assert_array_equal
2021
import pytest
21-
from ...testing import clear_and_catch_warnings, test_data
22+
from ...testing import test_data
2223
from .test_parse_gifti_fast import (DATA_FILE1, DATA_FILE2, DATA_FILE3,
2324
DATA_FILE4, DATA_FILE5, DATA_FILE6)
2425
import itertools
@@ -183,46 +184,29 @@ def test_dataarray_init():
183184

184185

185186
def test_dataarray_from_array():
186-
with clear_and_catch_warnings() as w:
187-
warnings.filterwarnings('always', category=DeprecationWarning)
188-
da = GiftiDataArray.from_array(np.ones((3, 4)))
189-
assert len(w) == 1
190-
for dt_code in data_type_codes.value_set():
191-
data_type = data_type_codes.type[dt_code]
192-
if data_type is np.void: # not supported
193-
continue
194-
arr = np.zeros((10, 3), dtype=data_type)
195-
da = GiftiDataArray.from_array(arr, 'triangle')
196-
assert da.datatype == data_type_codes[arr.dtype]
197-
bs_arr = arr.byteswap().newbyteorder()
198-
da = GiftiDataArray.from_array(bs_arr, 'triangle')
199-
assert da.datatype == data_type_codes[arr.dtype]
187+
with pytest.raises(ExpiredDeprecationError):
188+
GiftiDataArray.from_array(np.ones((3, 4)))
200189

201190

202191
def test_to_xml_open_close_deprecations():
203192
# Smoke test on deprecated functions
204193
da = GiftiDataArray(np.ones((1,)), 'triangle')
205-
with clear_and_catch_warnings() as w:
206-
warnings.filterwarnings('always', category=DeprecationWarning)
207-
assert isinstance(da.to_xml_open(), str)
208-
assert len(w) == 1
209-
with clear_and_catch_warnings() as w:
210-
warnings.filterwarnings('once', category=DeprecationWarning)
211-
assert isinstance(da.to_xml_close(), str)
212-
assert len(w) == 1
194+
with pytest.raises(ExpiredDeprecationError):
195+
da.to_xml_open()
196+
with pytest.raises(ExpiredDeprecationError):
197+
da.to_xml_close()
213198

214199

215200
def test_num_dim_deprecation():
216201
da = GiftiDataArray(np.ones((2, 3, 4)))
217202
# num_dim is property, set automatically from len(da.dims)
218203
assert da.num_dim == 3
219-
with clear_and_catch_warnings() as w:
220-
warnings.filterwarnings('always', category=DeprecationWarning)
221-
# OK setting num_dim to correct value, but raises DeprecationWarning
204+
# setting num_dim to correct value is deprecated
205+
with pytest.raises(ExpiredDeprecationError):
222206
da.num_dim = 3
223-
assert len(w) == 1
224-
# Any other value gives a ValueError
225-
pytest.raises(ValueError, setattr, da, 'num_dim', 4)
207+
# setting num_dim to incorrect value is also deprecated
208+
with pytest.raises(ExpiredDeprecationError):
209+
da.num_dim = 4
226210

227211

228212
def test_labeltable():
@@ -235,14 +219,10 @@ def test_labeltable():
235219
assert len(img.labeltable.labels) == 2
236220

237221
# Test deprecations
238-
with clear_and_catch_warnings() as w:
239-
warnings.filterwarnings('always', category=DeprecationWarning)
222+
with pytest.raises(ExpiredDeprecationError):
240223
newer_table = GiftiLabelTable()
241224
newer_table.labels += ['test', 'me', 'again']
242225
img.set_labeltable(newer_table)
243-
assert len(w) == 1
244-
assert len(img.get_labeltable().labels) == 3
245-
assert len(w) == 2
246226

247227

248228
def test_metadata():
@@ -261,14 +241,8 @@ def test_metadata():
261241
assert md.data[0].value == 'value'
262242
assert len(w) == 2
263243
# Test deprecation
264-
with clear_and_catch_warnings() as w:
265-
warnings.filterwarnings('always', category=DeprecationWarning)
266-
assert md.get_metadata() == dict(key='value')
267-
assert len(w) == 1
268-
assert md.metadata == dict(key='value')
269-
assert len(w) == 2
270-
assert len(GiftiDataArray().get_metadata()) == 0
271-
assert len(w) == 3
244+
with pytest.raises(ExpiredDeprecationError):
245+
md.get_metadata()
272246

273247

274248
def test_gifti_label_rgba():
@@ -295,10 +269,8 @@ def assign_rgba(gl, val):
295269
pytest.raises(ValueError, assign_rgba, gl3, rgba.tolist() + rgba.tolist())
296270

297271
# Test deprecation
298-
with clear_and_catch_warnings() as w:
299-
warnings.filterwarnings('once', category=DeprecationWarning)
300-
assert kwargs['red'] == gl3.get_rgba()[0]
301-
assert len(w) == 1
272+
with pytest.raises(ExpiredDeprecationError):
273+
gl3.get_rgba()
302274

303275
# Test default value
304276
gl4 = GiftiLabel()
@@ -325,10 +297,8 @@ def test_gifti_coord():
325297

326298

327299
def test_data_tag_deprecated():
328-
with clear_and_catch_warnings() as w:
329-
warnings.filterwarnings('once', category=DeprecationWarning)
300+
with pytest.raises(ExpiredDeprecationError):
330301
data_tag(np.array([]), 'ASCII', '%i', 1)
331-
assert len(w) == 1
332302

333303

334304
def test_gifti_round_trip():

nibabel/gifti/tests/test_giftiio.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@
77
#
88
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
99

10+
from ..gifti import GiftiImage
1011
from ..giftiio import read, write
1112
from .test_parse_gifti_fast import DATA_FILE1
13+
from ...deprecator import ExpiredDeprecationError
1214

1315
import pytest
1416

1517

1618
def test_read_deprecated(tmp_path):
17-
with pytest.deprecated_call():
18-
img = read(DATA_FILE1)
19+
with pytest.raises(ExpiredDeprecationError):
20+
read(DATA_FILE1)
1921

22+
img = GiftiImage.from_filename(DATA_FILE1)
2023
fname = tmp_path / 'test.gii'
21-
with pytest.deprecated_call():
24+
with pytest.raises(ExpiredDeprecationError):
2225
write(img, fname)

nibabel/gifti/tests/test_parse_gifti_fast.py

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from ...loadsave import load, save
2323
from ...nifti1 import xform_codes
2424
from ...tmpdirs import InTemporaryDirectory
25+
from ...deprecator import ExpiredDeprecationError
2526

2627
from numpy.testing import assert_array_almost_equal
2728

@@ -48,8 +49,8 @@
4849

4950
DATA_FILE1_darr1 = np.array(
5051
[[-16.07201, -66.187515, 21.266994],
51-
[-16.705893, -66.054337, 21.232786],
52-
[-17.614349, -65.401642, 21.071466]])
52+
[-16.705893, -66.054337, 21.232786],
53+
[-17.614349, -65.401642, 21.071466]])
5354
DATA_FILE1_darr2 = np.array([0, 1, 2])
5455

5556
DATA_FILE2_darr1 = np.array([[0.43635699],
@@ -189,14 +190,11 @@ def test_metadata_deprecations():
189190
me = img.meta
190191

191192
# Test deprecation
192-
with clear_and_catch_warnings() as w:
193-
warnings.filterwarnings('once', category=DeprecationWarning)
194-
assert me == img.get_meta()
193+
with pytest.raises(ExpiredDeprecationError):
194+
img.get_meta()
195195

196-
with clear_and_catch_warnings() as w:
197-
warnings.filterwarnings('once', category=DeprecationWarning)
196+
with pytest.raises(ExpiredDeprecationError):
198197
img.set_metadata(me)
199-
assert me == img.meta
200198

201199

202200
def test_load_dataarray1():
@@ -321,12 +319,8 @@ def test_load_getbyintent():
321319
da = img.get_arrays_from_intent("NIFTI_INTENT_POINTSET")
322320
assert len(da) == 1
323321

324-
with clear_and_catch_warnings() as w:
325-
warnings.filterwarnings('once', category=DeprecationWarning)
326-
da = img.getArraysFromIntent("NIFTI_INTENT_POINTSET")
327-
assert len(da) == 1
328-
assert len(w) == 1
329-
w[0].category == DeprecationWarning
322+
with pytest.raises(ExpiredDeprecationError):
323+
img.getArraysFromIntent("NIFTI_INTENT_POINTSET")
330324

331325
da = img.get_arrays_from_intent("NIFTI_INTENT_TRIANGLE")
332326
assert len(da) == 1
@@ -360,16 +354,11 @@ def test_labeltable_deprecations():
360354
lt = img.labeltable
361355

362356
# Test deprecation
363-
with clear_and_catch_warnings() as w:
364-
warnings.filterwarnings('always', category=DeprecationWarning)
365-
assert lt == img.get_labeltable()
366-
assert len(w) == 1
357+
with pytest.raises(ExpiredDeprecationError):
358+
img.get_labeltable()
367359

368-
with clear_and_catch_warnings() as w:
369-
warnings.filterwarnings('always', category=DeprecationWarning)
360+
with pytest.raises(ExpiredDeprecationError):
370361
img.set_labeltable(lt)
371-
assert len(w) == 1
372-
assert lt == img.labeltable
373362

374363

375364
def test_parse_dataarrays():
@@ -395,16 +384,11 @@ def test_parse_dataarrays():
395384
def test_parse_deprecated():
396385

397386
# Test deprecation
398-
with clear_and_catch_warnings() as w:
399-
warnings.filterwarnings('always', category=DeprecationWarning)
400-
op = Outputter()
401-
assert len(w) == 1
402-
op.initialize() # smoke test--no error.
403-
404-
with clear_and_catch_warnings() as w:
405-
warnings.filterwarnings('always', category=DeprecationWarning)
406-
pytest.raises(ValueError, parse_gifti_file)
407-
assert len(w) == 1
387+
with pytest.raises(ExpiredDeprecationError):
388+
Outputter()
389+
390+
with pytest.raises(ExpiredDeprecationError):
391+
parse_gifti_file()
408392

409393

410394
def test_parse_with_buffersize():

nibabel/nicom/tests/test_dicomwrappers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from .. import dicomwrappers as didw
1414
from .. import dicomreaders as didr
1515
from ...volumeutils import endian_codes
16+
from ...deprecator import ExpiredDeprecationError
1617

1718
import pytest
1819
from unittest import TestCase
@@ -631,8 +632,8 @@ def test_affine(self):
631632
# Make sure we find orientation/position/spacing info
632633
dw = didw.wrapper_from_file(DATA_FILE_4D)
633634
aff = dw.affine
634-
with pytest.deprecated_call():
635-
assert np.array_equal(dw.get_affine(), aff)
635+
with pytest.raises(ExpiredDeprecationError):
636+
dw.get_affine()
636637

637638
@dicom_test
638639
def test_data_real(self):

nibabel/streamlines/tests/test_array_sequence.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from numpy.testing import assert_array_equal
1111

1212
from ..array_sequence import ArraySequence, is_array_sequence, concatenate
13+
from ...deprecator import ExpiredDeprecationError
1314

1415

1516
SEQ_DATA = {}
@@ -96,7 +97,7 @@ def test_creating_arraysequence_from_list(self):
9697

9798
def test_deprecated_data_attribute(self):
9899
seq = ArraySequence(SEQ_DATA['data'])
99-
with pytest.deprecated_call(match="from version: 3.0"):
100+
with pytest.raises(ExpiredDeprecationError):
100101
seq.data
101102

102103
def test_creating_arraysequence_from_generator(self):

0 commit comments

Comments
 (0)