Skip to content

Commit

Permalink
Fixed bug validating stats elements in PandasInterface (#2199)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored Dec 15, 2017
1 parent 9959a1e commit 8106b49
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion holoviews/core/data/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def isscalar(cls, dataset, dim):

@classmethod
def validate(cls, dataset, vdims=True):
dim_types = 'key' if vdims else 'all'
dim_types = 'all' if vdims else 'key'
dimensions = dataset.dimensions(dim_types, label='name')
not_found = [d for d in dimensions if d not in dataset.data.columns]
if not_found:
Expand Down
32 changes: 29 additions & 3 deletions tests/teststatselements.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import numpy as np
from unittest import SkipTest

import holoviews
import numpy as np
import holoviews as hv
from holoviews.core.dimension import Dimension
from holoviews.core.options import Compositor, Store
from holoviews.core.util import pd
from holoviews.element import (Distribution, Bivariate, Points, Image,
Curve, Area, Contours, Polygons)
from holoviews.element.comparison import ComparisonTestCase
Expand All @@ -15,6 +17,18 @@ def test_distribution_array_constructor(self):
self.assertEqual(dist.kdims, [Dimension('Value')])
self.assertEqual(dist.vdims, [Dimension('Density')])

def test_distribution_dframe_constructor(self):
if pd is None:
raise SkipTest("Test requires pandas, skipping.")
dist = Distribution(pd.DataFrame({'Value': [0, 1, 2]}))
self.assertEqual(dist.kdims, [Dimension('Value')])
self.assertEqual(dist.vdims, [Dimension('Density')])

def test_distribution_dict_constructor(self):
dist = Distribution({'Value': [0, 1, 2]})
self.assertEqual(dist.kdims, [Dimension('Value')])
self.assertEqual(dist.vdims, [Dimension('Density')])

def test_distribution_array_constructor_custom_vdim(self):
dist = Distribution(np.array([0, 1, 2]), vdims=['Test'])
self.assertEqual(dist.kdims, [Dimension('Value')])
Expand All @@ -25,6 +39,18 @@ def test_bivariate_array_constructor(self):
self.assertEqual(dist.kdims, [Dimension('x'), Dimension('y')])
self.assertEqual(dist.vdims, [Dimension('Density')])

def test_bivariate_dframe_constructor(self):
if pd is None:
raise SkipTest("Test requires pandas, skipping.")
dist = Bivariate(pd.DataFrame({'x': [0, 1, 2], 'y': [0, 1, 2]}, columns=['x', 'y']))
self.assertEqual(dist.kdims, [Dimension('x'), Dimension('y')])
self.assertEqual(dist.vdims, [Dimension('Density')])

def test_bivariate_dict_constructor(self):
dist = Bivariate({'x': [0, 1, 2], 'y': [0, 1, 2]}, ['x', 'y'])
self.assertEqual(dist.kdims, [Dimension('x'), Dimension('y')])
self.assertEqual(dist.vdims, [Dimension('Density')])

def test_bivariate_array_constructor_custom_vdim(self):
dist = Bivariate(np.array([[0, 1, 2], [0, 1, 2]]), vdims=['Test'])
self.assertEqual(dist.kdims, [Dimension('x'), Dimension('y')])
Expand Down Expand Up @@ -82,7 +108,7 @@ def test_bivariate_from_points(self):
class StatisticalCompositorTest(ComparisonTestCase):

def setUp(self):
self.renderer = holoviews.renderer('matplotlib')
self.renderer = hv.renderer('matplotlib')
np.random.seed(42)

def test_distribution_composite(self):
Expand Down

0 comments on commit 8106b49

Please sign in to comment.