Skip to content

Commit

Permalink
Merge 8582118 into a4fb538
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Nov 15, 2020
2 parents a4fb538 + 8582118 commit 665c0bc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
7 changes: 7 additions & 0 deletions hvplot/plotting/core.py
Expand Up @@ -13,9 +13,16 @@


class hvPlotBase(object):

__all__ = []

def __init__(self, data, custom_plots={}, **metadata):
if 'query' in metadata:
data = data.query(metadata.pop('query'))
if 'sel' in metadata:
data = data.sel(**metadata.pop('sel'))
if 'isel' in metadata:
data = data.isel(**metadata.pop('isel'))
self._data = data
self._plots = custom_plots
self._metadata = metadata
Expand Down
40 changes: 39 additions & 1 deletion hvplot/tests/testoverrides.py
@@ -1,8 +1,18 @@
from collections import OrderedDict
from unittest import SkipTest

import numpy as np
import pandas as pd
from hvplot.plotting import hvPlotTabular

from hvplot.plotting import hvPlot, hvPlotTabular
from holoviews import Store, Scatter
from holoviews.element.comparison import ComparisonTestCase

try:
import xarray as xr
except:
xr = None


class TestOverrides(ComparisonTestCase):

Expand Down Expand Up @@ -42,3 +52,31 @@ def test_define_customize_method(self):
def test_attempt_to_override_kind_on_method(self):
hvplot = hvPlotTabular(self.df, {'scatter': {'kind': 'line'}})
self.assertIsInstance(hvplot.scatter(y='y'), Scatter)

def test_pandas_query_metadata(self):
hvplot = hvPlotTabular(self.df, query='x>2')
assert len(hvplot._data) == 2


class TestXArrayOverrides(ComparisonTestCase):

def setUp(self):
if xr is None:
raise SkipTest('XArray not available')
coords = OrderedDict([('time', [0, 1]), ('lat', [0, 1]), ('lon', [0, 1])])
self.da_img_by_time = xr.DataArray(np.arange(8).reshape((2, 2, 2)),
coords, ['time', 'lat', 'lon']).assign_coords(
lat1=xr.DataArray([2,3], dims=['lat']))

def test_xarray_isel_scalar_metadata(self):
hvplot = hvPlot(self.da_img_by_time, isel={'time': 1})
assert hvplot._data.ndim == 2

def test_xarray_isel_nonscalar_metadata(self):
hvplot = hvPlot(self.da_img_by_time, isel={'time': [1]})
assert hvplot._data.ndim == 3
assert len(hvplot._data.time) == 1

def test_xarray_sel_metadata(self):
hvplot = hvPlot(self.da_img_by_time, sel={'time': 1})
assert hvplot._data.ndim == 2

0 comments on commit 665c0bc

Please sign in to comment.