Skip to content

Commit

Permalink
Additional sanity checking for redimension() arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
tshead2 committed Aug 2, 2013
1 parent f1bc42d commit ef403c2
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions packages/slycat/analysis/coordinator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ def require_attributes(self, attributes):
else:
attributes = [self.require_attribute(attribute) for attribute in attributes]
return attributes
def require_attribute_names(self, names):
if isinstance(names, basestring):
return [self.require_attribute_name(names)]
return [self.require_attribute_name(name) for attribute_name in names]
def require_chunk_size(self, chunk_size):
if not isinstance(chunk_size, int):
raise InvalidArgument("Chunk size must be an integer.")
Expand All @@ -99,15 +103,14 @@ def require_chunk_sizes(self, shape, chunk_sizes):
if len(shape) != len(chunk_sizes):
raise InvalidArgument("Array shape and chunk sizes must contain the same number of dimensions.")
return chunk_sizes
def require_dimension(self, dimension):
if isinstance(dimension, basestring):
dimension = {"name":dimension, "type":"int64"}
return dimension
def require_dimensions(self, dimensions):
dimensions = [self.require_dimension(dimension) for dimension in dimensions]
if not len(dimensions):
raise InvalidArgument("Array must have at least one dimension.")
return dimensions
def require_dimension_name(self, name):
if not isinstance(name, basestring):
raise InvalidArgument("Dimension name must be a string.")
return name
def require_dimension_names(self, names):
if isinstance(names, basestring):
return [self.require_dimension_name(names)]
return [self.require_dimension_name(name) for name in names]
def require_expression(self, expression):
if isinstance(expression, basestring):
expression = ast.parse(expression)
Expand Down Expand Up @@ -236,6 +239,8 @@ def random(self, shape, chunk_sizes, seed, attributes):
return self.pyro_register(array(array_workers, []))
def redimension(self, source, dimensions, attributes):
source = self.require_object(source)
dimensions = self.require_dimension_names(dimensions)
attributes = self.require_attribute_names(attributes)
array_workers = []
for worker_index, (source_proxy, worker) in enumerate(zip(source.workers, self.workers())):
array_workers.append(worker.redimension(worker_index, source_proxy._pyroUri, dimensions, attributes))
Expand Down

0 comments on commit ef403c2

Please sign in to comment.