Skip to content

Commit

Permalink
Let holoviews set defaults for points (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsignell authored and philippjfr committed Jun 25, 2019
1 parent c4d29db commit b018152
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
8 changes: 5 additions & 3 deletions hvplot/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1272,8 +1272,9 @@ def points(self, x=None, y=None, data=None):
data = self.data if data is None else data
params = dict(self._relabel)

x = x or self.x
y = y or self.y
x = x if x is not None else self.x
y = y if y is not None else self.y

if hasattr(data, 'geom_type') and not (x and y):
x, y = 'Longitude', 'Latitude'

Expand All @@ -1291,11 +1292,12 @@ def points(self, x=None, y=None, data=None):
element = self._get_element('points')
if self.geo: params['crs'] = self.crs
vdims = [self.kwds['c']] if 'c' in self.kwds else []
kdims = [x, y] if x is not None and y is not None else None
if 's' in self.kwds:
vdims.append(self.kwds['s'])
vdims = vdims + self.hover_cols
params['vdims'] = vdims
return element(data, [x, y], **params).redim(**self._redim).redim.range(**ranges).opts(**opts)
return element(data, kdims, **params).redim(**self._redim).redim.range(**ranges).opts(**opts)

##########################
# Geometry plots #
Expand Down
27 changes: 26 additions & 1 deletion hvplot/tests/testcharts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,35 @@
from parameterized import parameterized

from holoviews import NdOverlay, Store
from holoviews.element import Curve, Area, Scatter
from holoviews.element import Curve, Area, Scatter, Points
from holoviews.element.comparison import ComparisonTestCase
from hvplot import patch

class TestChart2D(ComparisonTestCase):
def setUp(self):
try:
import pandas as pd
except:
raise SkipTest('Pandas not available')
patch('pandas')
self.df = pd.DataFrame([[1, 2], [3, 4], [5, 6]], columns=['x', 'y'])
self.cat_df = pd.DataFrame([[1, 2, 'A'], [3, 4, 'B'], [5, 6, 'C']],
columns=['x', 'y', 'category'])

@parameterized.expand([('points', Points)])
def test_tidy_chart_defaults(self, kind, element):
plot = self.df.hvplot(kind=kind)
self.assertEqual(plot, element(self.df))

@parameterized.expand([('points', Points)])
def test_tidy_chart(self, kind, element):
plot = self.df.hvplot(x='x', y='y', kind=kind)
self.assertEqual(plot, element(self.df, ['x', 'y']))

@parameterized.expand([('points', Points)])
def test_tidy_chart_index_and_c(self, kind, element):
plot = self.df.hvplot(x='index', y='y', c='x', kind=kind)
self.assertEqual(plot, element(self.df, ['index', 'y'], ['x']))

class TestChart1D(ComparisonTestCase):

Expand Down

0 comments on commit b018152

Please sign in to comment.