From 7364deea750be67f6bd8eb3c15d89a2149a4ebbc Mon Sep 17 00:00:00 2001
From: Philipp Rudiger
Date: Sat, 4 Jun 2016 18:12:47 +0100
Subject: [PATCH 1/4] Iris handles standard constructors enabling unit tests
---
holoviews/core/data/iris.py | 35 ++++++++++++++++++++++++++++-------
tests/testdataset.py | 34 +++++++++++++++++++++++++++++++++-
2 files changed, 61 insertions(+), 8 deletions(-)
diff --git a/holoviews/core/data/iris.py b/holoviews/core/data/iris.py
index 84e2ccffd4..273b6a8534 100644
--- a/holoviews/core/data/iris.py
+++ b/holoviews/core/data/iris.py
@@ -75,16 +75,18 @@ def init(cls, eltype, data, kdims, vdims):
kdim_names = [kd.name for kd in eltype.kdims]
if not isinstance(data, iris.cube.Cube):
+ ndims = len(kdim_names)
+ kdims = [kd if isinstance(kd, Dimension) else Dimension(kd)
+ for kd in kdims]
+ vdim = vdims[0].name if isinstance(vdims[0], Dimension) else vdims[0]
if isinstance(data, tuple):
- coords = [iris.coords.DimCoord(vals, long_name=kd)
- for kd, vals in zip(kdim_names, data)]
value_array = data[-1]
- vdim = vdims[0].name if isinstance(vdims[0], Dimension) else vdims[0]
+ data = {d: vals for d, vals in zip(kdim_names + [vdim], data)}
elif isinstance(data, dict):
- vdim = vdims[0].name if isinstance(vdims[0], Dimension) else vdims[0]
- coords = [iris.coords.DimCoord(vals, long_name=kd)
- for kd, vals in data.items() if kd in kdims]
value_array = data[vdim]
+ coords = [(iris.coords.DimCoord(data[kd.name], long_name=kd.name,
+ units=kd.unit), ndims-n-1)
+ for n, kd in enumerate(kdims)]
try:
data = iris.cube.Cube(value_array, long_name=vdim,
dim_coords_and_dims=coords)
@@ -222,6 +224,25 @@ def aggregate(cls, columns, kdims, function, **kwargs):
raise NotImplementedError
+ @classmethod
+ def sample(cls, dataset, samples=[]):
+ """
+ Sampling currently not implemented.
+ """
+ raise NotImplementedError
+
+
+ @classmethod
+ def add_dimension(cls, columns, dimension, dim_pos, values, vdim):
+ """
+ Adding value dimensions not currently supported by iris interface.
+ Adding key dimensions not possible on dense interfaces.
+ """
+ if not vdim:
+ raise Exception("Cannot add key dimension to a dense representation.")
+ raise NotImplementedError
+
+
@classmethod
def select_to_constraint(cls, selection):
"""
@@ -232,7 +253,7 @@ def select_to_constraint(cls, selection):
if isinstance(constraint, slice):
constraint = (constraint.start, constraint.stop)
if isinstance(constraint, tuple):
- constraint = iris.util.between(*constraint)
+ constraint = iris.util.between(*constraint, rh_inclusive=False)
constraint_kwargs[dim] = constraint
return iris.Constraint(**constraint_kwargs)
diff --git a/tests/testdataset.py b/tests/testdataset.py
index 54c5aa305a..9728410518 100644
--- a/tests/testdataset.py
+++ b/tests/testdataset.py
@@ -404,7 +404,7 @@ def test_dataset_double_zip_init(self):
class GridDatasetTest(HomogeneousColumnTypes, ComparisonTestCase):
"""
- Test of the NdDataset interface (mostly for backwards compatibility)
+ Test of the Grid array interface
"""
def setUp(self):
@@ -480,3 +480,35 @@ def test_dataset_sort_vdim_hm(self):
def test_dataset_groupby(self):
self.assertEqual(self.dataset_hm.groupby('x').keys(), list(self.xs))
+
+
+class IrisDatasetTest(GridDatasetTest):
+ """
+ Tests for Iris interface
+ """
+
+ def setUp(self):
+ import iris
+ self.restore_datatype = Dataset.datatype
+ Dataset.datatype = ['cube']
+ self.data_instance_type = iris.cube.Cube
+ self.init_data()
+
+ def test_dataset_add_dimensions_values_hm(self):
+ pass
+
+ def test_dataset_sort_vdim_hm(self):
+ pass
+
+ def test_dataset_1D_reduce_hm(self):
+ pass
+
+ def test_dataset_2D_reduce_hm(self):
+ pass
+
+ def test_dataset_2D_aggregate_partial_hm(self):
+ pass
+
+ def test_dataset_sample_hm(self):
+ pass
+
From 3e3cb4517ca1592c0f103a5a759c3a190a0b39d6 Mon Sep 17 00:00:00 2001
From: Philipp Rudiger
Date: Mon, 6 Jun 2016 15:27:19 +0100
Subject: [PATCH 2/4] Fixed iris interface tests
---
tests/testirisinterface.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/testirisinterface.py b/tests/testirisinterface.py
index 0e0b35e8c3..3ff71212dc 100644
--- a/tests/testirisinterface.py
+++ b/tests/testirisinterface.py
@@ -70,7 +70,7 @@ def test_select_index(self):
def test_select_slice(self):
cube = Dataset(self.cube)
- self.assertEqual(cube.select(longitude=(0, 1)).data.data,
+ self.assertEqual(cube.select(longitude=(0, 1.01)).data.data,
np.array([[1, 2], [5, 6], [9, 10]], dtype=np.int32))
def test_select_set(self):
@@ -84,8 +84,8 @@ def test_select_multi_index(self):
def test_select_multi_slice1(self):
cube = Dataset(self.cube)
- self.assertEqual(cube.select(longitude=(0, 1),
- latitude=(0, 1)).data.data,
+ self.assertEqual(cube.select(longitude=(0, 1.01),
+ latitude=(0, 1.01)).data.data,
np.array([[5, 6], [9, 10]], dtype=np.int32))
def test_select_multi_slice2(self):
From 5c1b5c7d69cbba514430a89382100b51a82e2ef8 Mon Sep 17 00:00:00 2001
From: Philipp Rudiger
Date: Mon, 6 Jun 2016 15:34:02 +0100
Subject: [PATCH 3/4] Ensure iris interface only returns scalar when indexed
---
holoviews/core/data/iris.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/holoviews/core/data/iris.py b/holoviews/core/data/iris.py
index 273b6a8534..c114d621a9 100644
--- a/holoviews/core/data/iris.py
+++ b/holoviews/core/data/iris.py
@@ -265,8 +265,9 @@ def select(cls, dataset, selection_mask=None, **selection):
"""
constraint = cls.select_to_constraint(selection)
pre_dim_coords = [c.name() for c in dataset.data.dim_coords]
+ indexed = cls.indexed(dataset, selection)
extracted = dataset.data.extract(constraint)
- if not extracted.dim_coords:
+ if indexed and not extracted.dim_coords:
return extracted.data.item()
post_dim_coords = [c.name() for c in extracted.dim_coords]
dropped = [c for c in pre_dim_coords if c not in post_dim_coords]
From a3a9f5946a1a31d8affe5121d6eeb0a7810b9848 Mon Sep 17 00:00:00 2001
From: Philipp Rudiger
Date: Thu, 9 Jun 2016 00:19:55 +0100
Subject: [PATCH 4/4] Small fixes to iris interface tests
---
tests/testdataset.py | 1 +
tests/testirisinterface.py | 7 ++++---
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/tests/testdataset.py b/tests/testdataset.py
index 9728410518..4b8e3b268e 100644
--- a/tests/testdataset.py
+++ b/tests/testdataset.py
@@ -494,6 +494,7 @@ def setUp(self):
self.data_instance_type = iris.cube.Cube
self.init_data()
+ # Disabled tests for NotImplemented methods
def test_dataset_add_dimensions_values_hm(self):
pass
diff --git a/tests/testirisinterface.py b/tests/testirisinterface.py
index 3ff71212dc..16315a6227 100644
--- a/tests/testirisinterface.py
+++ b/tests/testirisinterface.py
@@ -15,6 +15,7 @@ class TestCube(ComparisonTestCase):
def setUp(self):
self.cube = lat_lon_cube()
+ self.epsilon = 0.01
def test_dim_to_coord(self):
dim = coord_to_dimension(self.cube.coords()[0])
@@ -70,7 +71,7 @@ def test_select_index(self):
def test_select_slice(self):
cube = Dataset(self.cube)
- self.assertEqual(cube.select(longitude=(0, 1.01)).data.data,
+ self.assertEqual(cube.select(longitude=(0, 1+self.epsilon)).data.data,
np.array([[1, 2], [5, 6], [9, 10]], dtype=np.int32))
def test_select_set(self):
@@ -84,8 +85,8 @@ def test_select_multi_index(self):
def test_select_multi_slice1(self):
cube = Dataset(self.cube)
- self.assertEqual(cube.select(longitude=(0, 1.01),
- latitude=(0, 1.01)).data.data,
+ self.assertEqual(cube.select(longitude=(0, 1+self.epsilon),
+ latitude=(0, 1+self.epsilon)).data.data,
np.array([[5, 6], [9, 10]], dtype=np.int32))
def test_select_multi_slice2(self):