From 3e9a65bb684ca6d7fc640e12e64c1f378da65a30 Mon Sep 17 00:00:00 2001 From: "Timothy M. Shead" Date: Fri, 2 Aug 2013 00:22:19 -0600 Subject: [PATCH] Values() operator accepts attribute names and indexes. Closes #27. --- analysis-server/tests.py | 14 ++++++++++++++ packages/slycat/analysis/__init__.py | 11 ++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/analysis-server/tests.py b/analysis-server/tests.py index 8be1a2560..d9d61b328 100644 --- a/analysis-server/tests.py +++ b/analysis-server/tests.py @@ -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")]) diff --git a/packages/slycat/analysis/__init__.py b/packages/slycat/analysis/__init__.py index a2da59ea8..077032ac7 100644 --- a/packages/slycat/analysis/__init__.py +++ b/packages/slycat/analysis/__init__.py @@ -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 = []