Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented correct Raster.range #1255

Merged
merged 1 commit into from
Apr 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)))