Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita4724b7

Browse files
Merge pull request#468 from matthew-brett/back-compat-gifti
MRG: restore GiftiDataArray num_dim setterAdd back-compatibility setter for attribute moved to property.
2 parents82a261c +ba6f4ae commita4724b7

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

‎nibabel/gifti/gifti.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,17 @@ def __init__(self,
369369
defnum_dim(self):
370370
returnlen(self.dims)
371371

372+
# Setter for backwards compatibility with pymvpa
373+
@num_dim.setter
374+
defnum_dim(self,value):
375+
warnings.warn(
376+
"num_dim will be read-only in future versions of nibabel",
377+
DeprecationWarning,stacklevel=2)
378+
ifvalue!=len(self.dims):
379+
raiseValueError('num_dim value {0} != number of dimensions '
380+
'len(self.dims) {1}'
381+
.format(value,len(self.dims)))
382+
372383
@classmethod
373384
deffrom_array(klass,
374385
darray,

‎nibabel/gifti/tests/test_gifti.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,19 @@ def test_to_xml_open_close_deprecations():
182182
assert_equal(len(w),1)
183183

184184

185+
deftest_num_dim_deprecation():
186+
da=GiftiDataArray(np.ones((2,3,4)))
187+
# num_dim is property, set automatically from len(da.dims)
188+
assert_equal(da.num_dim,3)
189+
withclear_and_catch_warnings()asw:
190+
warnings.filterwarnings('always',category=DeprecationWarning)
191+
# OK setting num_dim to correct value, but raises DeprecationWarning
192+
da.num_dim=3
193+
assert_equal(len(w),1)
194+
# Any other value gives a ValueError
195+
assert_raises(ValueError,setattr,da,'num_dim',4)
196+
197+
185198
deftest_labeltable():
186199
img=GiftiImage()
187200
assert_equal(len(img.labeltable.labels),0)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp