Skip to content

Commit d7b5261

Browse files
authored
Merge pull request #1126 from effigies/fix/drop_nan2zero_arg
MNT: Expire ArrayWriter.to_fileobj(nan2zero=...) argument
2 parents e795be6 + f7fb99c commit d7b5261

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

nibabel/arraywriters.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@ def __init__(self, array, out_dtype=None)
2929
larger ints and smaller.
3030
"""
3131

32-
import warnings
33-
3432
import numpy as np
3533

3634
from .casting import (int_to_float, as_int, int_abs, type_info, floor_exact,
3735
best_float, shared_range)
3836
from .volumeutils import finite_range, array_to_file
37+
from .deprecator import ExpiredDeprecationError
3938

4039

4140
class WriterError(Exception):
@@ -192,11 +191,12 @@ def _check_nan2zero(self, nan2zero):
192191
if nan2zero != self._nan2zero:
193192
raise WriterError('Deprecated `nan2zero` argument to `to_fileobj` '
194193
'must be same as class value set in __init__')
195-
warnings.warn('Please remove `nan2zero` from call to ' '`to_fileobj` '
196-
'and use in instance __init__ instead.\n'
197-
'* deprecated in version: 2.0\n'
198-
'* will raise error in version: 4.0\n',
199-
DeprecationWarning, stacklevel=3)
194+
raise ExpiredDeprecationError(
195+
'Please remove `nan2zero` from call to `to_fileobj` '
196+
'and use in instance __init__ instead.\n'
197+
'* deprecated in version: 2.0\n'
198+
'* Raises ExpiredDeprecationError as of version: 4.0\n'
199+
)
200200

201201
def _needs_nan2zero(self):
202202
""" True if nan2zero check needed for writing array """

nibabel/tests/test_arraywriters.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
make_array_writer, get_slope_inter)
1414
from ..casting import int_abs, type_info, shared_range, on_powerpc
1515
from ..volumeutils import array_from_file, apply_read_scaling, _dt_min_max
16+
from ..deprecator import ExpiredDeprecationError
1617

1718
from numpy.testing import assert_array_almost_equal, assert_array_equal
1819
import pytest
19-
from ..testing import (assert_allclose_safely, suppress_warnings,
20-
error_warnings)
20+
from ..testing import assert_allclose_safely, suppress_warnings
2121

2222

2323
FLOAT_TYPES = np.sctypes['float']
@@ -506,12 +506,11 @@ def test_nan2zero():
506506
aw = awt(arr, np.float32, **kwargs)
507507
data_back = round_trip(aw)
508508
assert_array_equal(np.isnan(data_back), [True, False])
509-
# Deprecation warning for nan2zero as argument to `to_fileobj`
510-
with error_warnings():
511-
with pytest.deprecated_call():
512-
aw.to_fileobj(BytesIO(), 'F', True)
513-
with pytest.deprecated_call():
514-
aw.to_fileobj(BytesIO(), 'F', nan2zero=True)
509+
# Expired deprecation error for nan2zero as argument to `to_fileobj`
510+
with pytest.raises(ExpiredDeprecationError):
511+
aw.to_fileobj(BytesIO(), 'F', True)
512+
with pytest.raises(ExpiredDeprecationError):
513+
aw.to_fileobj(BytesIO(), 'F', nan2zero=True)
515514
# Error if nan2zero is not the value set at initialization
516515
with pytest.raises(WriterError):
517516
aw.to_fileobj(BytesIO(), 'F', False)
@@ -528,12 +527,11 @@ def test_nan2zero():
528527
data_back = round_trip(aw)
529528
astype_res = np.array(np.nan).astype(np.int32)
530529
assert_array_equal(data_back, [astype_res, 99])
531-
# Deprecation warning for nan2zero as argument to `to_fileobj`
532-
with error_warnings():
533-
with pytest.deprecated_call():
534-
aw.to_fileobj(BytesIO(), 'F', False)
535-
with pytest.deprecated_call():
536-
aw.to_fileobj(BytesIO(), 'F', nan2zero=False)
530+
# Expired deprecation error for nan2zero as argument to `to_fileobj`
531+
with pytest.raises(ExpiredDeprecationError):
532+
aw.to_fileobj(BytesIO(), 'F', False)
533+
with pytest.raises(ExpiredDeprecationError):
534+
aw.to_fileobj(BytesIO(), 'F', nan2zero=False)
537535
# Error if nan2zero is not the value set at initialization
538536
with pytest.raises(WriterError):
539537
aw.to_fileobj(BytesIO(), 'F', True)

nibabel/tests/test_removalschedule.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
("nibabel.ecat", "EcatImage", "from_filespec"),
6666
("nibabel.filebasedimages", "FileBasedImage", "get_header"),
6767
("nibabel.spatialimages", "SpatialImage", "get_affine"),
68+
("nibabel.arraywriters", "ArrayWriter", "_check_nan2zero"),
6869
]),
6970
("4.0.0", [("nibabel.dataobj_images", "DataobjImage", "get_shape"),
7071
("nibabel.filebasedimages", "FileBasedImage", "filespec_to_files"),

0 commit comments

Comments
 (0)