Skip to content

Commit

Permalink
Values() operator accepts attribute names and indexes. Closes #27.
Browse files Browse the repository at this point in the history
  • Loading branch information
tshead2 committed Aug 2, 2013
1 parent 40ae77a commit 3e9a65b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
14 changes: 14 additions & 0 deletions analysis-server/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,20 @@ def test_scan_null():
array1 = random(5)
scan(array1, format="null")

def test_values_default():
array1 = random(5, attributes=["foo", "bar"])
b = values(array1)

def test_values_index():
array1 = random(5, attributes=["foo", "bar"])
b = values(array1, 0)
c = values(array1, 1)

def test_values_name():
array1 = random(5, attributes=["foo", "bar"])
numpy.testing.assert_array_equal(values(array1, "foo"), values(array1, 0))
numpy.testing.assert_array_equal(values(array1, "bar"), values(array1, 1))

def test_zeros_1d():
array1 = zeros(5)
require_array_schema(array1, [("d0", "int64", 0, 5, 5)], [("val", "float64")])
Expand Down
11 changes: 10 additions & 1 deletion packages/slycat/analysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,19 @@ def value(self, source, attribute=0):
raise

def values(self, source, attribute=0):
"""Returns a remote array attribute as a numpy array.
"""Return an array attribute as a numpy array.
"""
start_time = time.time()

# Handle attribute names ...
if isinstance(attribute, basestring):
for index, array_attribute in enumerate(source.attributes):
if array_attribute["name"] == attribute:
attribute = index
break
else:
raise InvalidArgument("Not an attribute name: {}".format(attribute))

# Materialize every chunk into memory ...
chunk_coordinates = []
chunk_values = []
Expand Down

0 comments on commit 3e9a65b

Please sign in to comment.