Skip to content

Commit f7b96ac

Browse files
committed
RF+TST: deprecate get_affine method of image
Thanks to Chris M for reminding me.
1 parent 41a012f commit f7b96ac

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

nibabel/spatialimages.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,11 +627,12 @@ def get_data_dtype(self):
627627
def set_data_dtype(self, dtype):
628628
self._header.set_data_dtype(dtype)
629629

630+
@deprecate_with_version('get_affine method is deprecated.\n'
631+
'Please use the ``img.affine`` property '
632+
'instead.',
633+
'2.1', '4.0')
630634
def get_affine(self):
631635
""" Get affine from image
632-
633-
Please use the `affine` property instead of `get_affine`; we will
634-
deprecate this method in future versions of nibabel.
635636
"""
636637
return self.affine
637638

nibabel/tests/test_image_api.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,14 @@ def validate_affine(self, imaker, params):
113113
def validate_affine_deprecated(self, imaker, params):
114114
# Check deprecated affine API
115115
img = imaker()
116-
assert_almost_equal(img.get_affine(), params['affine'], 6)
117-
assert_equal(img.get_affine().dtype, np.float64)
118-
aff = img.get_affine()
119-
aff[0, 0] = 1.5
120-
assert_true(aff is img.get_affine())
116+
with clear_and_catch_warnings() as w:
117+
warnings.simplefilter('always', DeprecationWarning)
118+
assert_almost_equal(img.get_affine(), params['affine'], 6)
119+
assert_equal(len(w), 1)
120+
assert_equal(img.get_affine().dtype, np.float64)
121+
aff = img.get_affine()
122+
aff[0, 0] = 1.5
123+
assert_true(aff is img.get_affine())
121124

122125
def validate_header(self, imaker, params):
123126
# Check header API
@@ -134,9 +137,9 @@ def validate_header(self, imaker, params):
134137

135138
def validate_header_deprecated(self, imaker, params):
136139
# Check deprecated header API
140+
img = imaker()
137141
with clear_and_catch_warnings() as w:
138142
warnings.simplefilter('always', DeprecationWarning)
139-
img = imaker()
140143
hdr = img.get_header()
141144
assert_equal(len(w), 1)
142145
assert_true(hdr is img.header)

0 commit comments

Comments
 (0)