Skip to content

Commit

Permalink
Optimization for heatmap aggregation with pandas
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Mar 5, 2017
1 parent 1c80711 commit 8ba8dd6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions holoviews/core/data/__init__.py
Expand Up @@ -17,11 +17,13 @@
from .ndelement import NdElementInterface

datatypes = ['array', 'dictionary', 'grid', 'ndelement']
DF_INTERFACES = []

try:
import pandas as pd # noqa (Availability import)
from .pandas import PandasInterface
datatypes = ['array', 'dataframe', 'dictionary', 'grid', 'ndelement']
DF_INTERFACES.append(PandasInterface)
DFColumns = PandasInterface
except ImportError:
pass
Expand Down Expand Up @@ -49,6 +51,7 @@
try:
from .dask import DaskInterface
datatypes.append('dask')
DF_INTERFACES.append(DaskInterface)
except ImportError:
pass

Expand Down
7 changes: 6 additions & 1 deletion holoviews/element/util.py
Expand Up @@ -4,6 +4,7 @@
import numpy as np

from ..core import Dataset, OrderedDict
from ..core.data import DF_INTERFACES
from ..core.operation import ElementOperation
from ..core.util import (pd, is_nan, sort_topologically,
cartesian_product, is_cyclic, one_to_one)
Expand Down Expand Up @@ -134,7 +135,11 @@ def _aggregate_dataset(self, obj, xcoords, ycoords):
dtype = 'dataframe' if pd else 'dictionary'
dense_data = Dataset(data, kdims=obj.kdims, vdims=obj.vdims, datatype=[dtype])
concat_data = obj.interface.concatenate([dense_data, obj], datatype=[dtype])
agg = concat_data.reindex([xdim, ydim], vdims).aggregate([xdim, ydim], reduce_fn)
reindexed = concat_data.reindex([xdim, ydim], vdims)
if reindexed.interface in DF_INTERFACES:
agg = reindexed.clone(reindexed.data.groupby([xdim, ydim]).first().reset_index())
else:
agg = reindexed.aggregate([xdim, ydim], reduce_fn)

# Convert data to a gridded dataset
grid_data = {xdim: xcoords, ydim: ycoords}
Expand Down
4 changes: 2 additions & 2 deletions holoviews/operation/datashader.py
Expand Up @@ -20,12 +20,12 @@

from ..core import (ElementOperation, Element, Dimension, NdOverlay,
Overlay, CompositeOverlay, Dataset)
from ..core.data import ArrayInterface, PandasInterface, DaskInterface
from ..core.data import (ArrayInterface, PandasInterface, DaskInterface,
DF_INTERFACES)
from ..core.util import get_param_values, basestring
from ..element import GridImage, Image, Path, Curve, Contours, RGB
from ..streams import RangeXY

DF_INTERFACES = [PandasInterface, DaskInterface]

@dispatch(Element)
def discover(dataset):
Expand Down

0 comments on commit 8ba8dd6

Please sign in to comment.