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

Adding a max size for checking symmetry #340

Merged
merged 1 commit into from Oct 17, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions hvplot/converter.py
Expand Up @@ -153,6 +153,12 @@ class HoloViewsConverter(object):
the behavior.
sort_date (default=True): bool
Whether to sort the x-axis by date before plotting
symmetric (default=None): bool
Whether the data are symmetric around zero. If left unset, the data
will be checked for symmetry as long as the size is less than
``check_symmetric_max``.
check_symmetric_max (default=1000000):
Size above which to stop checking for symmetry by default on the data.

Datashader options
------------------
Expand Down Expand Up @@ -295,7 +301,7 @@ def __init__(self, data, x, y, kind=None, by=None, use_index=True,
dynspread=False, hover_cols=[], x_sampling=None,
y_sampling=None, project=False, tools=[],
attr_labels=None, coastline=False, tiles=False,
sort_date=True, **kwds):
sort_date=True, check_symmetric_max=1000000, **kwds):
# Process data and related options
self._redim = fields
self.use_index = use_index
Expand Down Expand Up @@ -450,7 +456,7 @@ def __init__(self, data, x, y, kind=None, by=None, use_index=True,
if (self.kind in self._colorbar_types or self.rasterize or self.datashade or self._color_dim):
try:
if not use_dask:
symmetric = self._process_symmetric(symmetric, clim)
symmetric = self._process_symmetric(symmetric, clim, check_symmetric_max)

if self._style_opts.get('cmap') is None:
if symmetric:
Expand Down Expand Up @@ -483,7 +489,7 @@ def __init__(self, data, x, y, kind=None, by=None, use_index=True,
param.main.warning('Plotting {kind} plot with parameters x: {x}, '
'y: {y}, by: {by}, groupby: {groupby}, row/col: {grid}'.format(**kwds))

def _process_symmetric(self, symmetric, clim):
def _process_symmetric(self, symmetric, clim, check_symmetric_max):
if symmetric is not None or clim is not None:
return symmetric

Expand All @@ -492,6 +498,9 @@ def _process_symmetric(self, symmetric, clim):
if self.data.chunks:
return False
data = self.data[self.z]
if data.size > check_symmetric_max:
return False

elif self._color_dim:
data = self.data[self._color_dim]
else:
Expand Down
15 changes: 15 additions & 0 deletions hvplot/tests/testgridplots.py
Expand Up @@ -36,6 +36,7 @@ def setUp(self):

self.xds_with_attrs = xr.Dataset({'light': self.xarr_with_attrs })
self.da_img = xr.DataArray(np.arange(-2, 2).reshape((2, 2)), name='foo')
self.big_img = xr.DataArray(np.arange(-1e6, 1e6).reshape(1000, 2000))

def test_rgb_dataarray_no_args(self):
rgb = self.da_rgb.hvplot()
Expand Down Expand Up @@ -140,3 +141,17 @@ def test_symmetric_img_with_cmap_set(self):
self.assertEqual(plot_opts.kwargs.get('symmetric'), True)
style_opts = Store.lookup_options('bokeh', plot, 'style')
self.assertEqual(style_opts.kwargs['cmap'], 'fire')

def test_symmetric_with_big_img_sets_symmetric_to_false_without_calculating(self):
plot = self.big_img.hvplot.image()
plot_opts = Store.lookup_options('bokeh', plot, 'plot')
self.assertEqual(plot_opts.kwargs.get('symmetric'), False)
style_opts = Store.lookup_options('bokeh', plot, 'style')
self.assertEqual(style_opts.kwargs['cmap'], 'kbc_r')

def test_symmetric_with_big_img_and_check_symmetric_max_calculates_symmetric(self):
plot = self.big_img.hvplot.image(check_symmetric_max=int(1e7))
plot_opts = Store.lookup_options('bokeh', plot, 'plot')
self.assertEqual(plot_opts.kwargs.get('symmetric'), True)
style_opts = Store.lookup_options('bokeh', plot, 'style')
self.assertEqual(style_opts.kwargs['cmap'], 'coolwarm')