1414from __future__ import division , print_function , absolute_import
1515
1616import sys
17- import warnings
1817
1918import numpy as np
2019
2322from ..nifti1 import data_type_codes , xform_codes , intent_codes
2423from .util import (array_index_order_codes , gifti_encoding_codes ,
2524 gifti_endian_codes , KIND2FMT )
25+ from ..deprecated import deprecate_with_version
2626
2727# {en,de}codestring in deprecated in Python3, but
2828# {en,de}codebytes not available in Python2.
@@ -47,7 +47,10 @@ def from_dict(klass, data_dict):
4747 meda .data .append (nv )
4848 return meda
4949
50- @np .deprecate_with_doc ("Use the metadata property instead." )
50+ @deprecate_with_version (
51+ 'get_metadata method deprecated. '
52+ "Use the metadata property instead."
53+ '2.1' , '4.0' )
5154 def get_metadata (self ):
5255 return self .metadata
5356
@@ -156,7 +159,10 @@ def __init__(self, key=0, red=None, green=None, blue=None, alpha=None):
156159 self .blue = blue
157160 self .alpha = alpha
158161
159- @np .deprecate_with_doc ("Use the rgba property instead." )
162+ @deprecate_with_version (
163+ 'get_rgba method deprecated. '
164+ "Use the rgba property instead."
165+ '2.1' , '4.0' )
160166 def get_rgba (self ):
161167 return self .rgba
162168
@@ -249,7 +255,9 @@ def print_summary(self):
249255 print ('Affine Transformation Matrix: \n ' , self .xform )
250256
251257
252- @np .deprecate_with_doc ("This is an internal API that will be discontinued." )
258+ @deprecate_with_version (
259+ "data_tag is an internal API that will be discontinued." ,
260+ '2.1' , '4.0' )
253261def data_tag (dataarray , encoding , datatype , ordering ):
254262 class DataTag (xml .XmlSerializable ):
255263
@@ -371,16 +379,20 @@ def num_dim(self):
371379
372380 # Setter for backwards compatibility with pymvpa
373381 @num_dim .setter
382+ @deprecate_with_version (
383+ "num_dim will be read-only in future versions of nibabel" ,
384+ '2.1' , '4.0' )
374385 def num_dim (self , value ):
375- warnings .warn (
376- "num_dim will be read-only in future versions of nibabel" ,
377- DeprecationWarning , stacklevel = 2 )
378386 if value != len (self .dims ):
379387 raise ValueError ('num_dim value {0} != number of dimensions '
380388 'len(self.dims) {1}'
381389 .format (value , len (self .dims )))
382390
383391 @classmethod
392+ @deprecate_with_version (
393+ 'from_array method is deprecated. '
394+ 'Please use GiftiDataArray constructor instead.' ,
395+ '2.1' , '4.0' )
384396 def from_array (klass ,
385397 darray ,
386398 intent = "NIFTI_INTENT_NONE" ,
@@ -419,10 +431,6 @@ def from_array(klass,
419431 -------
420432 da : instance of our own class
421433 """
422- warnings .warn (
423- "Please use GiftiDataArray constructor instead of from_array "
424- "class method" ,
425- DeprecationWarning , stacklevel = 2 )
426434 return klass (data = darray ,
427435 intent = intent ,
428436 datatype = datatype ,
@@ -463,7 +471,10 @@ def _to_xml_element(self):
463471
464472 return data_array
465473
466- @np .deprecate_with_doc ("Use the to_xml() function instead." )
474+ @deprecate_with_version (
475+ 'to_xml_open method deprecated. '
476+ 'Use the to_xml() function instead.' ,
477+ '2.1' , '4.0' )
467478 def to_xml_open (self ):
468479 out = """<DataArray Intent="%s"
469480\t DataType="%s"
@@ -487,7 +498,10 @@ def to_xml_open(self):
487498 self .ext_offset ,
488499 )
489500
490- @np .deprecate_with_doc ("Use the to_xml() function instead." )
501+ @deprecate_with_version (
502+ 'to_xml_close method deprecated. '
503+ 'Use the to_xml() function instead.' ,
504+ '2.1' , '4.0' )
491505 def to_xml_close (self ):
492506 return "</DataArray>\n "
493507
@@ -507,7 +521,10 @@ def print_summary(self):
507521 print ('Coordinate System:' )
508522 print (self .coordsys .print_summary ())
509523
510- @np .deprecate_with_doc ("Use the metadata property instead." )
524+ @deprecate_with_version (
525+ 'get_metadata method deprecated. '
526+ "Use the metadata property instead."
527+ '2.1' , '4.0' )
511528 def get_metadata (self ):
512529 return self .meta .metadata
513530
@@ -591,11 +608,17 @@ def labeltable(self, labeltable):
591608 raise TypeError ("Not a valid GiftiLabelTable instance" )
592609 self ._labeltable = labeltable
593610
594- @np .deprecate_with_doc ("Use the gifti_img.labeltable property instead." )
611+ @deprecate_with_version (
612+ 'set_labeltable method deprecated. '
613+ "Use the gifti_img.labeltable property instead." ,
614+ '2.1' , '4.0' )
595615 def set_labeltable (self , labeltable ):
596616 self .labeltable = labeltable
597617
598- @np .deprecate_with_doc ("Use the gifti_img.labeltable property instead." )
618+ @deprecate_with_version (
619+ 'get_labeltable method deprecated. '
620+ "Use the gifti_img.labeltable property instead." ,
621+ '2.1' , '4.0' )
599622 def get_labeltable (self ):
600623 return self .labeltable
601624
@@ -615,11 +638,17 @@ def meta(self, meta):
615638 raise TypeError ("Not a valid GiftiMetaData instance" )
616639 self ._meta = meta
617640
618- @np .deprecate_with_doc ("Use the gifti_img.labeltable property instead." )
641+ @deprecate_with_version (
642+ 'set_meta method deprecated. '
643+ "Use the gifti_img.meta property instead." ,
644+ '2.1' , '4.0' )
619645 def set_metadata (self , meta ):
620646 self .meta = meta
621647
622- @np .deprecate_with_doc ("Use the gifti_img.labeltable property instead." )
648+ @deprecate_with_version (
649+ 'get_meta method deprecated. '
650+ "Use the gifti_img.meta property instead." ,
651+ '2.1' , '4.0' )
623652 def get_meta (self ):
624653 return self .meta
625654
@@ -651,7 +680,10 @@ def get_arrays_from_intent(self, intent):
651680 it = intent_codes .code [intent ]
652681 return [x for x in self .darrays if x .intent == it ]
653682
654- @np .deprecate_with_doc ("Use get_arrays_from_intent instead." )
683+ @deprecate_with_version (
684+ 'getArraysFromIntent method deprecated. '
685+ "Use get_arrays_from_intent instead." ,
686+ '2.1' , '4.0' )
655687 def getArraysFromIntent (self , intent ):
656688 return self .get_arrays_from_intent (intent )
657689
0 commit comments