Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

added validation on identifiers input

This commit is contained in:
Arnar Flatberg 2007-03-14 16:06:16 +00:00
parent 51435d9fdc
commit 00dd3e8d9d
1 changed files with 18 additions and 12 deletions

View File

@ -49,13 +49,9 @@ class Dataset:
if array.shape[0]==1: if array.shape[0]==1:
array = array.T array = array.T
self.shape = array.shape self.shape = array.shape
if identifiers!=None: if identifiers!=None:
identifier_shape = [len(i[1]) for i in identifiers] self._validate_identifiers(identifiers)
if len(identifier_shape)!=len(self.shape):
raise ValueError, "Identifier list length must equal array dims"
for ni, na in zip(identifier_shape, self.shape):
if ni!=na:
raise ValueError, "identifier-array mismatch in %s: (idents: %s, array: %s)" %(self._name, ni, na)
self._set_identifiers(identifiers, self._all_dims) self._set_identifiers(identifiers, self._all_dims)
else: else:
self._identifiers = self._create_identifiers(self.shape, self._all_dims) self._identifiers = self._create_identifiers(self.shape, self._all_dims)
@ -197,6 +193,17 @@ class Dataset:
""" """
return copy.deepcopy(self) return copy.deepcopy(self)
def _validate_identifiers(self, identifiers):
for dim_name, ids in identifiers:
if len(set(ids)) != len(ids):
raise ValueError("Identifiers not unique in : %s" %dim_name)
identifier_shape = [len(i[1]) for i in identifiers]
if len(identifier_shape)!=len(self.shape):
raise ValueError("Identifier list length must equal array dims")
for ni, na in zip(identifier_shape, self.shape):
if ni != na:
raise ValueError, "Identifier-array mismatch: %s: (idents: %s, array: %s)" %(self._name, ni, na)
class CategoryDataset(Dataset): class CategoryDataset(Dataset):
"""The category dataset class. """The category dataset class.
@ -490,4 +497,3 @@ def read_ftsv(fd):
return ds return ds