Skip to content

Commit dcd4c80

Browse files
author
Ben Cipollini
committed
make num_dim a read-only property
1 parent 76f1453 commit dcd4c80

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

nibabel/gifti/gifti.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ class GiftiDataArray(xml.XmlSerializable):
233233
intent = int
234234
datatype = int
235235
ind_ord = int
236-
num_dim = int
237236
dims = list
238237
encoding = int
239238
endian = int
@@ -266,6 +265,9 @@ def __init__(self, data=None,
266265
self.encoding = encoding
267266
self.endian = endian
268267

268+
@property
269+
def num_dim(self):
270+
return len(self.dims)
269271

270272
@classmethod
271273
def from_array(klass,
@@ -309,7 +311,6 @@ def from_array(klass,
309311
if meta is None:
310312
meta = {}
311313
cda = klass(darray)
312-
cda.num_dim = len(darray.shape)
313314
cda.dims = list(darray.shape)
314315
if datatype is None:
315316
cda.datatype = data_type_codes.code[darray.dtype]

nibabel/gifti/parse_gifti_fast.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,14 @@ def StartElementHandler(self, name, attrs):
167167
if "ArrayIndexingOrder" in attrs:
168168
self.da.ind_ord = array_index_order_codes.code[
169169
attrs["ArrayIndexingOrder"]]
170-
if "Dimensionality" in attrs:
171-
self.da.num_dim = int(attrs["Dimensionality"])
172-
for i in range(self.da.num_dim):
170+
num_dim = int(attrs.get("Dimensionality", 0))
171+
for i in range(num_dim):
173172
di = "Dim%s" % str(i)
174173
if di in attrs:
175174
self.da.dims.append(int(attrs[di]))
176175
# dimensionality has to correspond to the number of DimX given
177-
assert len(self.da.dims) == self.da.num_dim
176+
# TODO (bcipolli): don't assert; raise parse warning, and recover.
177+
assert len(self.da.dims) == num_dim
178178
if "Encoding" in attrs:
179179
self.da.encoding = gifti_encoding_codes.code[attrs["Encoding"]]
180180
if "Endian" in attrs:

0 commit comments

Comments
 (0)