Skip to content

Commit bc5f38f

Browse files
author
Ben Cipollini
committed
Add get_/set_ function deprecations and deprecation tests.
1 parent 1effc55 commit bc5f38f

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

nibabel/gifti/gifti.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,14 @@ def labeltable(self, labeltable):
380380
raise ValueError("Not a valid GiftiLabelTable instance")
381381
self._labeltable = labeltable
382382

383+
@np.deprecate_with_doc("Use the gifti_img.labeltable property instead.")
384+
def set_labeltable(self, labeltable):
385+
self.labeltable = labeltable
386+
387+
@np.deprecate_with_doc("Use the gifti_img.labeltable property instead.")
388+
def get_labeltable(self):
389+
return self.labeltable
390+
383391
@property
384392
def meta(self):
385393
return self._meta
@@ -400,6 +408,14 @@ def meta(self, meta):
400408
raise ValueError("Not a valid GiftiMetaData instance")
401409
self._meta = meta
402410

411+
@np.deprecate_with_doc("Use the gifti_img.labeltable property instead.")
412+
def set_metadata(self, meta):
413+
self.meta = meta
414+
415+
@np.deprecate_with_doc("Use the gifti_img.labeltable property instead.")
416+
def get_meta(self):
417+
return self.meta
418+
403419
def add_gifti_data_array(self, dataarr):
404420
""" Adds a data array to the GiftiImage
405421

nibabel/gifti/tests/test_giftiio.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,21 @@ def test_load_metadata():
117117
assert_equal(img.version,'1.0')
118118

119119

120+
def test_metadata_deprecations():
121+
img = gi.read(datafiles[0])
122+
me = img.meta
123+
124+
# Test deprecation
125+
with clear_and_catch_warnings() as w:
126+
warnings.filterwarnings('once', category=DeprecationWarning)
127+
assert_equal(me, img.get_meta())
128+
129+
with clear_and_catch_warnings() as w:
130+
warnings.filterwarnings('once', category=DeprecationWarning)
131+
img.set_metadata(me)
132+
assert_equal(me, img.meta)
133+
134+
120135
def test_load_dataarray1():
121136
img1 = gi.read(DATA_FILE1)
122137

@@ -270,3 +285,18 @@ def test_load_labeltable():
270285
assert_equal(img.labeltable.labels[1].green, 0.392157)
271286
assert_equal(img.labeltable.labels[1].blue, 0.156863)
272287
assert_equal(img.labeltable.labels[1].alpha, 1)
288+
289+
290+
def test_labeltable_deprecations():
291+
img = gi.read(DATA_FILE6)
292+
lt = img.labeltable
293+
294+
# Test deprecation
295+
with clear_and_catch_warnings() as w:
296+
warnings.filterwarnings('once', category=DeprecationWarning)
297+
assert_equal(lt, img.get_labeltable())
298+
299+
with clear_and_catch_warnings() as w:
300+
warnings.filterwarnings('once', category=DeprecationWarning)
301+
img.set_labeltable(lt)
302+
assert_equal(lt, img.labeltable)

0 commit comments

Comments
 (0)