Skip to content

RF+TST: restore GiftiDataArray num_dim setter #468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions nibabel/gifti/gifti.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,17 @@ def __init__(self,
def num_dim(self):
return len(self.dims)

# Setter for backwards compatibility with pymvpa
@num_dim.setter
def num_dim(self, value):
warnings.warn(
"num_dim will be read-only in future versions of nibabel",
DeprecationWarning, stacklevel=2)
if value != len(self.dims):
raise ValueError('num_dim value {0} != number of dimensions '
'len(self.dims) {1}'
.format(value, len(self.dims)))

@classmethod
def from_array(klass,
darray,
Expand Down
13 changes: 13 additions & 0 deletions nibabel/gifti/tests/test_gifti.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,19 @@ def test_to_xml_open_close_deprecations():
assert_equal(len(w), 1)


def test_num_dim_deprecation():
da = GiftiDataArray(np.ones((2, 3, 4)))
# num_dim is property, set automatically from len(da.dims)
assert_equal(da.num_dim, 3)
with clear_and_catch_warnings() as w:
warnings.filterwarnings('always', category=DeprecationWarning)
# OK setting num_dim to correct value, but raises DeprecationWarning
da.num_dim = 3
assert_equal(len(w), 1)
# Any other value gives a ValueError
assert_raises(ValueError, setattr, da, 'num_dim', 4)


def test_labeltable():
img = GiftiImage()
assert_equal(len(img.labeltable.labels), 0)
Expand Down