Skip to content

Commit

Permalink
Fixed lower bound inclusivity bug when no upper bound supplied (#1686)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored and jlstevens committed Jul 6, 2017
1 parent 199ea09 commit 0770184
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
4 changes: 2 additions & 2 deletions holoviews/core/ndmapping.py
Expand Up @@ -705,9 +705,9 @@ def _upto_condition(self, slice):

def _from_condition(self, slice):
if slice.step is None:
lmbd = lambda x: x > slice.start
lmbd = lambda x: x >= slice.start
else:
lmbd = lambda x: x > slice.start and ((x-slice.start) % slice.step)
lmbd = lambda x: x >= slice.start and ((x-slice.start) % slice.step)
return lmbd

def _all_condition(self):
Expand Down
34 changes: 33 additions & 1 deletion tests/testndmapping.py
@@ -1,7 +1,7 @@
from collections import OrderedDict

from holoviews.core import Dimension
from holoviews.core.ndmapping import MultiDimensionalMapping
from holoviews.core.ndmapping import MultiDimensionalMapping, NdMapping
from holoviews.element.comparison import ComparisonTestCase
from holoviews import HoloMap, Dataset
import numpy as np
Expand Down Expand Up @@ -88,6 +88,38 @@ def test_idxmapping_nested_update(self):
nested_ndmap[1.5] = ndmap3
self.assertEquals(list(nested_ndmap[1.5].values()), ['e', 'f'])

def test_ndmapping_slice_lower_bound_inclusive_int(self):
ndmap = NdMapping(self.init_item_odict, kdims=[self.dim1, self.dim2])
self.assertEqual(ndmap[1:].keys(), [(1, 2.0), (5, 3.0)])

def test_ndmapping_slice_lower_bound_inclusive2_int(self):
ndmap = NdMapping(self.init_item_odict, kdims=[self.dim1, self.dim2])
self.assertEqual(ndmap[1:6].keys(), [(1, 2.0), (5, 3.0)])

def test_ndmapping_slice_upper_bound_exclusive_int(self):
ndmap = NdMapping(self.init_item_odict, kdims=[self.dim1, self.dim2])
self.assertEqual(ndmap[1:5].keys(), [(1, 2.0)])

def test_ndmapping_slice_upper_bound_exclusive2_int(self):
ndmap = NdMapping(self.init_item_odict, kdims=[self.dim1, self.dim2])
self.assertEqual(ndmap[:5].keys(), [(1, 2.0)])

def test_ndmapping_slice_lower_bound_inclusive_float(self):
ndmap = NdMapping(self.init_item_odict, kdims=[self.dim1, self.dim2])
self.assertEqual(ndmap[:, 2.0:].keys(), [(1, 2.0), (5, 3.0)])

def test_ndmapping_slice_lower_bound_inclusive2_float(self):
ndmap = NdMapping(self.init_item_odict, kdims=[self.dim1, self.dim2])
self.assertEqual(ndmap[:, 2.0:5.0].keys(), [(1, 2.0), (5, 3.0)])

def test_ndmapping_slice_upper_bound_exclusive_float(self):
ndmap = NdMapping(self.init_item_odict, kdims=[self.dim1, self.dim2])
self.assertEqual(ndmap[:, :3.0].keys(), [(1, 2.0)])

def test_ndmapping_slice_upper_bound_exclusive2_float(self):
ndmap = NdMapping(self.init_item_odict, kdims=[self.dim1, self.dim2])
self.assertEqual(ndmap[:, 0.0:3.0].keys(), [(1, 2.0)])

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

0 comments on commit 0770184

Please sign in to comment.