Skip to content

Commit fcd2816

Browse files
committed
MNT: Deprecate GiftiMetaData.data and GiftiNVPairs
These really should have been deprecated, instead of FutureWarning'd. Keeping them around will cause confusion at best.
1 parent ed5c468 commit fcd2816

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

nibabel/gifti/gifti.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,11 @@ def _sanitize(args, kwargs):
108108
return (), {pair.name: pair.value}
109109

110110
@property
111+
@deprecate_with_version(
112+
'The data attribute is deprecated. Use GiftiMetaData object '
113+
'directly as a dict.',
114+
'4.0', '6.0')
111115
def data(self):
112-
warnings.warn(
113-
"GiftiMetaData.data will be a dict in NiBabel 6.0.",
114-
FutureWarning, stacklevel=2)
115116
return _GiftiMDList(self)
116117

117118
@classmethod
@@ -130,7 +131,7 @@ def get_metadata(self):
130131

131132
@property
132133
@deprecate_with_version(
133-
'metadata property deprecated. Use GiftiMetadata object '
134+
'metadata property deprecated. Use GiftiMetaData object '
134135
'as dict or pass to dict() for a standard dictionary.',
135136
'4.0', '6.0')
136137
def metadata(self):
@@ -149,14 +150,21 @@ class GiftiNVPairs:
149150
name : str
150151
value : str
151152
"""
153+
@deprecate_with_version(
154+
'GiftiNVPairs objects are deprecated. Use the GiftiMetaData object '
155+
'as a dict, instead.',
156+
'4.0', '6.0')
152157
def __init__(self, name=u'', value=u''):
153158
self._name = name
154159
self._value = value
155160
self._container = None
156161

157162
@classmethod
158163
def _private_init(cls, name, value, md):
159-
self = cls(name, value)
164+
"""Private init method to provide warning-free experience"""
165+
with warnings.catch_warnings():
166+
warnings.simplefilter('ignore', DeprecationWarning)
167+
self = cls(name, value)
160168
self._container = md
161169
return self
162170

nibabel/gifti/tests/test_gifti.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,16 @@ def test_labeltable():
228228
def test_metadata():
229229
md = GiftiMetaData(key='value')
230230
# Old initialization methods
231-
nvpair = GiftiNVPairs('key', 'value')
231+
with pytest.warns(DeprecationWarning) as w:
232+
nvpair = GiftiNVPairs('key', 'value')
232233
with pytest.warns(FutureWarning) as w:
233234
md2 = GiftiMetaData(nvpair=nvpair)
234235
assert len(w) == 1
235236
with pytest.warns(DeprecationWarning) as w:
236237
md3 = GiftiMetaData.from_dict({'key': 'value'})
237238
assert md == md2 == md3 == {'key': 'value'}
238239
# .data as a list of NVPairs is going away
239-
with pytest.warns(FutureWarning) as w:
240+
with pytest.warns(DeprecationWarning) as w:
240241
assert md.data[0].name == 'key'
241242
assert md.data[0].value == 'value'
242243
assert len(w) == 2
@@ -247,7 +248,7 @@ def test_metadata():
247248

248249
def test_metadata_list_interface():
249250
md = GiftiMetaData(key='value')
250-
with pytest.warns(FutureWarning):
251+
with pytest.warns(DeprecationWarning):
251252
mdlist = md.data
252253
assert len(mdlist) == 1
253254
assert mdlist[0].name == 'key'
@@ -264,7 +265,8 @@ def test_metadata_list_interface():
264265
assert md['foo'] == 'bar'
265266

266267
# Append new NVPair
267-
nvpair = GiftiNVPairs('key', 'value')
268+
with pytest.warns(DeprecationWarning) as w:
269+
nvpair = GiftiNVPairs('key', 'value')
268270
mdlist.append(nvpair)
269271
assert len(mdlist) == 2
270272
assert mdlist[1].name == 'key'
@@ -278,14 +280,16 @@ def test_metadata_list_interface():
278280
assert len(md) == 0
279281

280282
# Extension adds multiple keys
281-
foobar = GiftiNVPairs('foo', 'bar')
283+
with pytest.warns(DeprecationWarning) as w:
284+
foobar = GiftiNVPairs('foo', 'bar')
282285
mdlist.extend([nvpair, foobar])
283286
assert len(mdlist) == 2
284287
assert len(md) == 2
285288
assert md == {'key': 'value', 'foo': 'bar'}
286289

287290
# Insertion updates list order, though we don't attempt to preserve it in the dict
288-
lastone = GiftiNVPairs('last', 'one')
291+
with pytest.warns(DeprecationWarning) as w:
292+
lastone = GiftiNVPairs('last', 'one')
289293
mdlist.insert(1, lastone)
290294
assert len(mdlist) == 3
291295
assert len(md) == 3
@@ -314,7 +318,8 @@ def test_metadata_list_interface():
314318
assert md == {'last': 'one'}
315319

316320
# And let's remove an old pair with a new object
317-
lastoneagain = GiftiNVPairs('last', 'one')
321+
with pytest.warns(DeprecationWarning) as w:
322+
lastoneagain = GiftiNVPairs('last', 'one')
318323
mdlist.remove(lastoneagain)
319324
assert len(mdlist) == 0
320325
assert len(md) == 0

nibabel/tests/test_removalschedule.py

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
]
1313

1414
OBJECT_SCHEDULE = [
15+
("7.0.0", [("nibabel.gifti.gifti", "GiftiNVPairs"),
16+
]),
1517
("6.0.0", [("nibabel.loadsave", "guessed_image_type"),
1618
("nibabel.loadsave", "read_img_data"),
1719
("nibabel.orientations", "flip_axis"),
@@ -41,6 +43,7 @@
4143
ATTRIBUTE_SCHEDULE = [
4244
("7.0.0", [("nibabel.gifti.gifti", "GiftiMetaData", "from_dict"),
4345
("nibabel.gifti.gifti", "GiftiMetaData", "metadata"),
46+
("nibabel.gifti.gifti", "GiftiMetaData", "data"),
4447
]),
4548
("5.0.0", [("nibabel.dataobj_images", "DataobjImage", "get_data"),
4649
("nibabel.freesurfer.mghformat", "MGHHeader", "_header_data"),

0 commit comments

Comments
 (0)