Skip to content

Commit 6699a43

Browse files
author
Ben Cipollini
committed
get_metadata => metadata
1 parent bc5f38f commit 6699a43

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

nibabel/gifti/gifti.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ def from_dict(klass, data_dict):
3838
meda.data.append(nv)
3939
return meda
4040

41+
@np.deprecate_with_doc("Use the metadata property instead.")
4142
def get_metadata(self):
43+
return self.metadata
44+
45+
@property
46+
def metadata(self):
4247
""" Returns metadata as dictionary """
4348
self.data_as_dict = {}
4449
for ele in self.data:
@@ -59,7 +64,7 @@ def to_xml(self):
5964
return res
6065

6166
def print_summary(self):
62-
print(self.get_metadata())
67+
print(self.metadata)
6368

6469

6570
class GiftiNVPairs(object):
@@ -338,9 +343,14 @@ def print_summary(self):
338343
print('Coordinate System:')
339344
print(self.coordsys.print_summary())
340345

346+
@np.deprecate_with_doc("Use the metadata property instead.")
341347
def get_metadata(self):
348+
return self.meta.metadata
349+
350+
@property
351+
def metadata(self):
342352
""" Returns metadata as dictionary """
343-
return self.meta.get_metadata()
353+
return self.meta.metadata
344354

345355

346356
class GiftiImage(object):

nibabel/gifti/tests/test_gifti.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
""" Testing gifti objects
22
"""
3+
import warnings
34

45
import numpy as np
56

7+
from .. import giftiio as gi
8+
from ..gifti import (GiftiImage, GiftiDataArray, GiftiLabel, GiftiLabelTable,
9+
GiftiMetaData)
610
from ...nifti1 import data_type_codes, intent_codes
711

8-
from ..gifti import GiftiImage, GiftiDataArray, GiftiLabelTable
9-
1012
from numpy.testing import (assert_array_almost_equal,
1113
assert_array_equal)
12-
1314
from nose.tools import assert_true, assert_equal, assert_raises
15+
from ...testing import clear_and_catch_warnings
1416

1517

1618
def test_gifti_image():
@@ -47,3 +49,18 @@ def test_labeltable():
4749
img.labeltable = new_table
4850
assert_equal(len(img.labeltable.labels), 2)
4951

52+
# Try to set to non-table
53+
with assert_raises(ValueError):
54+
img.labeltable = 'not-a-table'
55+
56+
57+
def test_metadata():
58+
# Test deprecation
59+
with clear_and_catch_warnings() as w:
60+
warnings.filterwarnings('once', category=DeprecationWarning)
61+
assert_equal(len(GiftiDataArray().get_metadata()), 0)
62+
63+
# Test deprecation
64+
with clear_and_catch_warnings() as w:
65+
warnings.filterwarnings('once', category=DeprecationWarning)
66+
assert_equal(len(GiftiMetaData().get_metadata()), 0)

nibabel/gifti/tests/test_giftiio.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def test_load_dataarray1():
142142
for img in (img1, bimg):
143143
assert_array_almost_equal(img.darrays[0].data, DATA_FILE1_darr1)
144144
assert_array_almost_equal(img.darrays[1].data, DATA_FILE1_darr2)
145-
me=img.darrays[0].meta.get_metadata()
145+
me=img.darrays[0].meta.metadata
146146
assert_true('AnatomicalStructurePrimary' in me)
147147
assert_true('AnatomicalStructureSecondary' in me)
148148
assert_equal(me['AnatomicalStructurePrimary'], 'CortexLeft')
@@ -237,11 +237,11 @@ def test_write_newmetadata():
237237
attr = gi.GiftiNVPairs(name = 'mykey', value = 'val1')
238238
newmeta = gi.GiftiMetaData(attr)
239239
img.meta = newmeta
240-
myme = img.meta.get_metadata()
240+
myme = img.meta.metadata
241241
assert_true('mykey' in myme)
242242
newmeta = gi.GiftiMetaData.from_dict( {'mykey1' : 'val2'} )
243243
img.meta = newmeta
244-
myme = img.meta.get_metadata()
244+
myme = img.meta.metadata
245245
assert_true('mykey1' in myme)
246246
assert_false('mykey' in myme)
247247

0 commit comments

Comments
 (0)