Skip to content

Commit

Permalink
Improved tests for grid concatenation
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Jun 20, 2018
1 parent a96e32c commit 67bd62a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
22 changes: 22 additions & 0 deletions tests/core/data/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import numpy as np

from holoviews import Dataset, HoloMap, Dimension
from holoviews.core.data import concat
from holoviews.core.data.interface import DataError
from holoviews.element import Scatter, Curve
from holoviews.element.comparison import ComparisonTestCase

Expand Down Expand Up @@ -1081,3 +1083,23 @@ def test_aggregate_2d_with_spreadfn(self):
agg = ds.aggregate('x', np.mean, np.std)
example = Dataset((range(5), array.mean(axis=0), array.std(axis=0)), 'x', ['z', 'z_std'])
self.assertEqual(agg, example)

def test_concat_grid_3d(self):
array = np.random.rand(4, 5, 3, 2)
orig = Dataset((range(2), range(3), range(5), range(4), array), ['A', 'B', 'x', 'y'], 'z')
hmap = HoloMap({(i, j): self.element((range(5), range(4), array[:, :, j, i]), ['x', 'y'], 'z')
for i in range(2) for j in range(3)}, ['A', 'B'])
ds = concat(hmap)
self.assertEqual(ds, orig)

def test_concat_grid_3d_shape_mismatch(self):
ds1 = Dataset(([0, 1], [1, 2, 3], np.random.rand(3, 2)), ['x', 'y'], 'z')
ds2 = Dataset(([0, 1, 2], [1, 2], np.random.rand(2, 3)), ['x', 'y'], 'z')
hmap = HoloMap({1: ds1, 2: ds2})
with self.assertRaises(DataError):
concat(hmap)

def test_grid_3d_groupby_concat_roundtrip(self):
array = np.random.rand(4, 5, 3, 2)
orig = Dataset((range(2), range(3), range(5), range(4), array), ['A', 'B', 'x', 'y'], 'z')
self.assertEqual(concat(orig.groupby(['A', 'B'])), orig)
13 changes: 12 additions & 1 deletion tests/core/data/testirisinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
try:
import iris
from iris.tests.stock import lat_lon_cube
from iris.exceptions import MergeError
except ImportError:
raise SkipTest("Could not import iris, skipping IrisInterface tests.")

from holoviews.core.data import Dataset
from holoviews.core.data import Dataset, concat
from holoviews.core.data.iris import coord_to_dimension
from holoviews.core.spaces import HoloMap
from holoviews.element import Image

from .testimageinterface import Image_ImageInterfaceTests
Expand All @@ -30,6 +32,15 @@ def init_data(self):
self.cube = lat_lon_cube()
self.epsilon = 0.01

def test_concat_grid_3d_shape_mismatch(self):
arr1 = np.random.rand(3, 2)
arr2 = np.random.rand(2, 3)
ds1 = Dataset(([0, 1], [1, 2, 3], arr1), ['x', 'y'], 'z')
ds2 = Dataset(([0, 1, 2], [1, 2], arr2), ['x', 'y'], 'z')
hmap = HoloMap({1: ds1, 2: ds2})
with self.assertRaises(MergeError):
concat(hmap)

def test_dataset_array_init_hm(self):
"Tests support for arrays (homogeneous)"
raise SkipTest("Not supported")
Expand Down
15 changes: 14 additions & 1 deletion tests/core/data/testxarrayinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
except:
raise SkipTest("Could not import xarray, skipping XArrayInterface tests.")

from holoviews.core.data import Dataset
from holoviews.core.data import Dataset, concat
from holoviews.core.dimension import Dimension
from holoviews.core.spaces import HoloMap
from holoviews.element import Image, RGB, HSV

from .testimageinterface import (
Expand Down Expand Up @@ -109,6 +110,18 @@ def test_xarray_coord_ordering(self):
ds = Dataset(dataset)
self.assertEqual(ds.kdims, ['b', 'c', 'a'])

def test_concat_grid_3d_shape_mismatch(self):
arr1 = np.random.rand(3, 2)
arr2 = np.random.rand(2, 3)
ds1 = Dataset(([0, 1], [1, 2, 3], arr1), ['x', 'y'], 'z')
ds2 = Dataset(([0, 1, 2], [1, 2], arr2), ['x', 'y'], 'z')
hmap = HoloMap({1: ds1, 2: ds2})
arr = np.full((3, 3, 2), np.NaN)
arr[:, :2, 0] = arr1
arr[:2, :, 1] = arr2
ds = Dataset(([1, 2], [0, 1, 2], [1, 2, 3], arr), ['Default', 'x', 'y'], 'z')
self.assertEqual(concat(hmap), ds)

def test_dataset_array_init_hm(self):
"Tests support for arrays (homogeneous)"
raise SkipTest("Not supported")
Expand Down

0 comments on commit 67bd62a

Please sign in to comment.