Skip to content

Commit e2bd1e5

Browse files
author
Ben Cipollini
committed
deprecate (not delete) to_xml_start, to_xml_end
1 parent 81b7b2b commit e2bd1e5

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

nibabel/gifti/gifti.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,34 @@ def _to_xml_element(self):
330330

331331
return data_array
332332

333+
@np.deprecate_with_doc("Use the to_xml() function instead.")
334+
def to_xml_open(self):
335+
out = """<DataArray Intent="%s"
336+
\tDataType="%s"
337+
\tArrayIndexingOrder="%s"
338+
\tDimensionality="%s"
339+
%s\tEncoding="%s"
340+
\tEndian="%s"
341+
\tExternalFileName="%s"
342+
\tExternalFileOffset="%s">\n"""
343+
di = ""
344+
for i, n in enumerate(self.dims):
345+
di = di + '\tDim%s=\"%s\"\n' % (str(i), str(n))
346+
return out % (intent_codes.niistring[self.intent],
347+
data_type_codes.niistring[self.datatype],
348+
array_index_order_codes.label[self.ind_ord],
349+
str(self.num_dim),
350+
str(di),
351+
gifti_encoding_codes.specs[self.encoding],
352+
gifti_endian_codes.specs[self.endian],
353+
self.ext_fname,
354+
self.ext_offset,
355+
)
356+
357+
@np.deprecate_with_doc("Use the to_xml() function instead.")
358+
def to_xml_close(self):
359+
return "</DataArray>\n"
360+
333361
def print_summary(self):
334362
print('Intent: ', intent_codes.niistring[self.intent])
335363
print('DataType: ', data_type_codes.niistring[self.datatype])

nibabel/gifti/tests/test_gifti.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import numpy as np
66

7+
from nibabel.externals.six import string_types
78
from nibabel.gifti import (GiftiImage, GiftiDataArray, GiftiLabel,
89
GiftiLabelTable, GiftiMetaData, giftiio)
910
from nibabel.gifti.gifti import data_tag
@@ -70,6 +71,17 @@ def test_dataarray():
7071
da = GiftiDataArray.from_array(bs_arr, 'triangle')
7172
assert_equal(da.datatype, data_type_codes[arr.dtype])
7273

74+
# Smoke test on deprecated functions
75+
da = GiftiDataArray.from_array(np.ones((1,)), 'triangle')
76+
with clear_and_catch_warnings() as w:
77+
warnings.filterwarnings('always', category=DeprecationWarning)
78+
assert_true(isinstance(da.to_xml_open(), string_types))
79+
assert_equal(len(w), 1)
80+
with clear_and_catch_warnings() as w:
81+
warnings.filterwarnings('once', category=DeprecationWarning)
82+
assert_true(isinstance(da.to_xml_close(), string_types))
83+
assert_equal(len(w), 1)
84+
7385

7486
def test_labeltable():
7587
img = GiftiImage()

0 commit comments

Comments
 (0)