Skip to content

Commit

Permalink
Added tests and ValueError for (un)sorted NdMappings
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Mar 24, 2017
1 parent 16068e4 commit 8f539ec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions holoviews/core/ndmapping.py
Expand Up @@ -109,6 +109,10 @@ def __init__(self, initial_items=None, **params):
self._cached_categorical = any(d.values for d in self.kdims)

if initial_items is None: initial_items = []
if type(initial_items) is dict and not sort:
raise ValueError('If sort=False the data must define a fixed '
'ordering, please supply a list of items or '
'an OrderedDict, not a regular dictionary.')
if isinstance(initial_items, tuple):
self._add_item(initial_items[0], initial_items[1])
elif not self._check_items:
Expand Down
17 changes: 17 additions & 0 deletions tests/testndmapping.py
Expand Up @@ -88,6 +88,23 @@ def test_idxmapping_nested_update(self):
nested_ndmap[1.5] = ndmap3
self.assertEquals(list(nested_ndmap[1.5].values()), ['e', 'f'])

def test_idxmapping_unsorted(self):
data = [('B', 1), ('C', 2), ('A', 3)]
ndmap = MultiDimensionalMapping(data, sort=False)
self.assertEquals(ndmap.keys(), ['B', 'C', 'A'])

def test_idxmapping_unsorted_clone(self):
data = [('B', 1), ('C', 2), ('A', 3)]
ndmap = MultiDimensionalMapping(data, sort=False).clone()
self.assertEquals(ndmap.keys(), ['B', 'C', 'A'])

def test_idxmapping_groupby_unsorted(self):
data = [(('B', 2), 1), (('C', 2), 2), (('A', 1), 3)]
grouped = MultiDimensionalMapping(data, sort=False, kdims=['X', 'Y']).groupby('Y')
self.assertEquals(grouped.keys(), [1, 2])
self.assertEquals(grouped.values()[0].keys(), ['A'])
self.assertEquals(grouped.last.keys(), ['B', 'C'])

def test_idxmapping_reindex(self):
data = [((0, 0.5), 'a'), ((1, 0.5), 'b')]
ndmap = MultiDimensionalMapping(data, kdims=[self.dim1, self.dim2])
Expand Down

0 comments on commit 8f539ec

Please sign in to comment.