Skip to content

Commit

Permalink
Implemented correct Raster.range
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Apr 10, 2017
1 parent 2e6e31b commit 76e7d55
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
17 changes: 16 additions & 1 deletion holoviews/element/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Overlay, Element, Dataset, NdElement)
from ..core.boundingregion import BoundingRegion, BoundingBox
from ..core.sheetcoords import SheetCoordinateSystem
from ..core.util import pd
from ..core.util import pd, max_range
from .chart import Curve
from .tabular import Table
from .util import compute_edges, compute_slice_bounds, categorical_aggregate2d
Expand Down Expand Up @@ -76,6 +76,21 @@ def __getitem__(self, slices):
extents=None)


def range(self, dim, data_range=True):
idx = self.get_dimension_index(dim)
if data_range and idx == 2:
dimension = self.get_dimension(dim)
drange = self.data.min(), self.data.max()
drange = max_range([drange, dimension.soft_range])
if dimension.range[0] is not None:
return (dimension.range[0], drange[1])
elif dimension.range[1] is not None:
return (drange[0], dimension.range[1])
else:
return drange
return super(Raster, self).range(dim, data_range)


def dimension_values(self, dim, expanded=True, flat=True):
"""
The set of samples available along a particular dimension.
Expand Down
12 changes: 12 additions & 0 deletions tests/testraster.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,15 @@ def test_image_sample(self):
self.assertEqual(image.sample(y=0.25),
Curve(np.array([(-0.333333, 0), (0, 1), (0.333333, 2)]),
kdims=['x'], vdims=['z']))

def test_raster_range_masked(self):
arr = np.random.rand(10,10)-0.5
arr = np.ma.masked_where(arr<=0, arr)
rrange = Raster(arr).range(2)
self.assertEqual(rrange, (np.min(arr), np.max(arr)))

def test_image_range_masked(self):
arr = np.random.rand(10,10)-0.5
arr = np.ma.masked_where(arr<=0, arr)
rrange = Image(arr).range(2)
self.assertEqual(rrange, (np.min(arr), np.max(arr)))

0 comments on commit 76e7d55

Please sign in to comment.