Skip to content

Commit eeaa4ba

Browse files
committed
MNT: Complete various GIFTI removals
1 parent 3aaf8d1 commit eeaa4ba

File tree

4 files changed

+0
-221
lines changed

4 files changed

+0
-221
lines changed

nibabel/gifti/gifti.py

Lines changed: 0 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,6 @@ def data(self):
122122
def from_dict(klass, data_dict):
123123
return klass(data_dict)
124124

125-
@deprecate_with_version(
126-
'get_metadata method deprecated. '
127-
"Use the metadata property instead.",
128-
'2.1', '4.0')
129-
def get_metadata(self):
130-
return dict(self)
131-
132125
@property
133126
@deprecate_with_version(
134127
'metadata property deprecated. Use GiftiMetaData object '
@@ -274,13 +267,6 @@ def __repr__(self):
274267
r, g, b, a = chars.astype('u1')
275268
return f'<GiftiLabel {self.key}="#{r:02x}{g:02x}{b:02x}{a:02x}">'
276269

277-
@deprecate_with_version(
278-
'get_rgba method deprecated. '
279-
"Use the rgba property instead.",
280-
'2.1', '4.0')
281-
def get_rgba(self):
282-
return self.rgba
283-
284270
@property
285271
def rgba(self):
286272
""" Returns RGBA as tuple """
@@ -488,68 +474,6 @@ def __repr__(self):
488474
def num_dim(self):
489475
return len(self.dims)
490476

491-
# Setter for backwards compatibility with pymvpa
492-
@num_dim.setter
493-
@deprecate_with_version(
494-
"num_dim will be read-only in future versions of nibabel",
495-
'2.1', '4.0')
496-
def num_dim(self, value):
497-
if value != len(self.dims):
498-
raise ValueError(f'num_dim value {value} != number of '
499-
f'dimensions len(self.dims) {len(self.dims)}')
500-
501-
@classmethod
502-
@deprecate_with_version(
503-
'from_array method is deprecated. '
504-
'Please use GiftiDataArray constructor instead.',
505-
'2.1', '4.0')
506-
def from_array(klass,
507-
darray,
508-
intent="NIFTI_INTENT_NONE",
509-
datatype=None,
510-
encoding="GIFTI_ENCODING_B64GZ",
511-
endian=sys.byteorder,
512-
coordsys=None,
513-
ordering="C",
514-
meta=None):
515-
""" Creates a new Gifti data array
516-
517-
Parameters
518-
----------
519-
darray : ndarray
520-
NumPy data array
521-
intent : string
522-
NIFTI intent code, see nifti1.intent_codes
523-
datatype : None or string, optional
524-
NIFTI data type codes, see nifti1.data_type_codes
525-
If None, the datatype of the NumPy array is taken.
526-
encoding : string, optionaal
527-
Encoding of the data, see util.gifti_encoding_codes;
528-
default: GIFTI_ENCODING_B64GZ
529-
endian : string, optional
530-
The Endianness to store the data array. Should correspond to the
531-
machine endianness. default: system byteorder
532-
coordsys : GiftiCoordSystem, optional
533-
If None, a identity transformation is taken.
534-
ordering : string, optional
535-
The ordering of the array. see util.array_index_order_codes;
536-
default: RowMajorOrder - C ordering
537-
meta : None or dict, optional
538-
A dictionary for metadata information. If None, gives empty dict.
539-
540-
Returns
541-
-------
542-
da : instance of our own class
543-
"""
544-
return klass(data=darray,
545-
intent=intent,
546-
datatype=datatype,
547-
encoding=encoding,
548-
endian=endian,
549-
coordsys=coordsys,
550-
ordering=ordering,
551-
meta=meta)
552-
553477
def _to_xml_element(self):
554478
# fix endianness to machine endianness
555479
self.endian = gifti_endian_codes.code[sys.byteorder]
@@ -580,40 +504,6 @@ def _to_xml_element(self):
580504

581505
return data_array
582506

583-
@deprecate_with_version(
584-
'to_xml_open method deprecated. '
585-
'Use the to_xml() function instead.',
586-
'2.1', '4.0')
587-
def to_xml_open(self):
588-
out = """<DataArray Intent="%s"
589-
\tDataType="%s"
590-
\tArrayIndexingOrder="%s"
591-
\tDimensionality="%s"
592-
%s\tEncoding="%s"
593-
\tEndian="%s"
594-
\tExternalFileName="%s"
595-
\tExternalFileOffset="%d">\n"""
596-
di = ""
597-
for i, n in enumerate(self.dims):
598-
di = di + f'\tDim{i}="{n}\"\n'
599-
return out % (intent_codes.niistring[self.intent],
600-
data_type_codes.niistring[self.datatype],
601-
array_index_order_codes.label[self.ind_ord],
602-
str(self.num_dim),
603-
str(di),
604-
gifti_encoding_codes.specs[self.encoding],
605-
gifti_endian_codes.specs[self.endian],
606-
self.ext_fname,
607-
self.ext_offset,
608-
)
609-
610-
@deprecate_with_version(
611-
'to_xml_close method deprecated. '
612-
'Use the to_xml() function instead.',
613-
'2.1', '4.0')
614-
def to_xml_close(self):
615-
return "</DataArray>\n"
616-
617507
def print_summary(self):
618508
print('Intent: ', intent_codes.niistring[self.intent])
619509
print('DataType: ', data_type_codes.niistring[self.datatype])
@@ -630,13 +520,6 @@ def print_summary(self):
630520
print('Coordinate System:')
631521
print(self.coordsys.print_summary())
632522

633-
@deprecate_with_version(
634-
'get_metadata method deprecated. '
635-
"Use the metadata property instead.",
636-
'2.1', '4.0')
637-
def get_metadata(self):
638-
return dict(self.meta)
639-
640523
@property
641524
def metadata(self):
642525
""" Returns metadata as dictionary """
@@ -718,20 +601,6 @@ def labeltable(self, labeltable):
718601
raise TypeError("Not a valid GiftiLabelTable instance")
719602
self._labeltable = labeltable
720603

721-
@deprecate_with_version(
722-
'set_labeltable method deprecated. '
723-
"Use the gifti_img.labeltable property instead.",
724-
'2.1', '4.0')
725-
def set_labeltable(self, labeltable):
726-
self.labeltable = labeltable
727-
728-
@deprecate_with_version(
729-
'get_labeltable method deprecated. '
730-
"Use the gifti_img.labeltable property instead.",
731-
'2.1', '4.0')
732-
def get_labeltable(self):
733-
return self.labeltable
734-
735604
@property
736605
def meta(self):
737606
return self._meta
@@ -748,20 +617,6 @@ def meta(self, meta):
748617
raise TypeError("Not a valid GiftiMetaData instance")
749618
self._meta = meta
750619

751-
@deprecate_with_version(
752-
'set_meta method deprecated. '
753-
"Use the gifti_img.meta property instead.",
754-
'2.1', '4.0')
755-
def set_metadata(self, meta):
756-
self.meta = meta
757-
758-
@deprecate_with_version(
759-
'get_meta method deprecated. '
760-
"Use the gifti_img.meta property instead.",
761-
'2.1', '4.0')
762-
def get_meta(self):
763-
return self.meta
764-
765620
def add_gifti_data_array(self, dataarr):
766621
""" Adds a data array to the GiftiImage
767622
@@ -925,13 +780,6 @@ def agg_data(self, intent_code=None):
925780

926781
return all_data
927782

928-
@deprecate_with_version(
929-
'getArraysFromIntent method deprecated. '
930-
"Use get_arrays_from_intent instead.",
931-
'2.1', '4.0')
932-
def getArraysFromIntent(self, intent):
933-
return self.get_arrays_from_intent(intent)
934-
935783
def print_summary(self):
936784
print('----start----')
937785
print('Source filename: ', self.get_filename())

nibabel/gifti/tests/test_gifti.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
GiftiCoordSystem)
1515
from ...nifti1 import data_type_codes
1616
from ...fileholders import FileHolder
17-
from ...deprecator import ExpiredDeprecationError
1817

1918
from numpy.testing import assert_array_almost_equal, assert_array_equal
2019
import pytest
@@ -182,32 +181,6 @@ def test_dataarray_init():
182181
assert gda(ext_offset=12).ext_offset == 12
183182

184183

185-
def test_dataarray_from_array():
186-
with pytest.raises(ExpiredDeprecationError):
187-
GiftiDataArray.from_array(np.ones((3, 4)))
188-
189-
190-
def test_to_xml_open_close_deprecations():
191-
# Smoke test on deprecated functions
192-
da = GiftiDataArray(np.ones((1,)), 'triangle')
193-
with pytest.raises(ExpiredDeprecationError):
194-
da.to_xml_open()
195-
with pytest.raises(ExpiredDeprecationError):
196-
da.to_xml_close()
197-
198-
199-
def test_num_dim_deprecation():
200-
da = GiftiDataArray(np.ones((2, 3, 4)))
201-
# num_dim is property, set automatically from len(da.dims)
202-
assert da.num_dim == 3
203-
# setting num_dim to correct value is deprecated
204-
with pytest.raises(ExpiredDeprecationError):
205-
da.num_dim = 3
206-
# setting num_dim to incorrect value is also deprecated
207-
with pytest.raises(ExpiredDeprecationError):
208-
da.num_dim = 4
209-
210-
211184
def test_labeltable():
212185
img = GiftiImage()
213186
assert len(img.labeltable.labels) == 0
@@ -217,12 +190,6 @@ def test_labeltable():
217190
img.labeltable = new_table
218191
assert len(img.labeltable.labels) == 2
219192

220-
# Test deprecations
221-
with pytest.raises(ExpiredDeprecationError):
222-
newer_table = GiftiLabelTable()
223-
newer_table.labels += ['test', 'me', 'again']
224-
img.set_labeltable(newer_table)
225-
226193

227194
def test_metadata():
228195
md = GiftiMetaData(key='value')
@@ -240,9 +207,6 @@ def test_metadata():
240207
assert md.data[0].name == 'key'
241208
assert md.data[0].value == 'value'
242209
assert len(w) == 2
243-
# Test deprecation
244-
with pytest.raises(ExpiredDeprecationError):
245-
md.get_metadata()
246210

247211

248212
def test_metadata_list_interface():
@@ -347,10 +311,6 @@ def assign_rgba(gl, val):
347311
pytest.raises(ValueError, assign_rgba, gl3, rgba[:2])
348312
pytest.raises(ValueError, assign_rgba, gl3, rgba.tolist() + rgba.tolist())
349313

350-
# Test deprecation
351-
with pytest.raises(ExpiredDeprecationError):
352-
gl3.get_rgba()
353-
354314
# Test default value
355315
gl4 = GiftiLabel()
356316
assert len(gl4.rgba) == 4

nibabel/gifti/tests/test_parse_gifti_fast.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,6 @@ def test_load_metadata():
185185
assert img.version == '1.0'
186186

187187

188-
def test_metadata_deprecations():
189-
img = load(datafiles[0])
190-
me = img.meta
191-
192-
# Test deprecation
193-
with pytest.raises(ExpiredDeprecationError):
194-
img.get_meta()
195-
196-
with pytest.raises(ExpiredDeprecationError):
197-
img.set_metadata(me)
198-
199-
200188
def test_load_dataarray1():
201189
img1 = load(DATA_FILE1)
202190
# Round trip
@@ -319,9 +307,6 @@ def test_load_getbyintent():
319307
da = img.get_arrays_from_intent("NIFTI_INTENT_POINTSET")
320308
assert len(da) == 1
321309

322-
with pytest.raises(ExpiredDeprecationError):
323-
img.getArraysFromIntent("NIFTI_INTENT_POINTSET")
324-
325310
da = img.get_arrays_from_intent("NIFTI_INTENT_TRIANGLE")
326311
assert len(da) == 1
327312

@@ -349,18 +334,6 @@ def test_load_labeltable():
349334
assert img.labeltable.labels[1].alpha == 1
350335

351336

352-
def test_labeltable_deprecations():
353-
img = load(DATA_FILE6)
354-
lt = img.labeltable
355-
356-
# Test deprecation
357-
with pytest.raises(ExpiredDeprecationError):
358-
img.get_labeltable()
359-
360-
with pytest.raises(ExpiredDeprecationError):
361-
img.set_labeltable(lt)
362-
363-
364337
def test_parse_dataarrays():
365338
fn = 'bad_daa.gii'
366339
img = gi.GiftiImage()

nibabel/tests/test_removalschedule.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
]),
4848
("5.0.0", [("nibabel.dataobj_images", "DataobjImage", "get_data"),
4949
("nibabel.freesurfer.mghformat", "MGHHeader", "_header_data"),
50-
("nibabel.gifti.gifti", "GiftiDataArray", "num_dim"),
5150
("nibabel.gifti.gifti", "GiftiDataArray", "from_array"),
5251
("nibabel.gifti.gifti", "GiftiDataArray", "to_xml_open"),
5352
("nibabel.gifti.gifti", "GiftiDataArray", "to_xml_close"),
@@ -57,7 +56,6 @@
5756
("nibabel.gifti.gifti", "GiftiImage", "get_metadata"),
5857
("nibabel.gifti.gifti", "GiftiImage", "set_metadata"),
5958
("nibabel.gifti.gifti", "GiftiImage", "getArraysFromIntent"),
60-
("nibabel.gifti.gifti", "GiftiImage", "getArraysFromIntent"),
6159
("nibabel.gifti.gifti", "GiftiMetaData", "get_metadata"),
6260
("nibabel.gifti.gifti", "GiftiLabel", "get_rgba"),
6361
("nibabel.nicom.dicomwrappers", "Wrapper", "get_affine"),

0 commit comments

Comments
 (0)