Skip to content

Commit

Permalink
Made timeseries operation efficient for Pandas and DaskInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Mar 3, 2017
1 parent faf9a0b commit 838012d
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion holoviews/operation/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@
from ..core.util import pd
from ..element import Scatter

DF_INTERFACES = []
try:
from ..core.data import PandasInterface
DF_INTERFACES.append(PandasInterface)
except:
pass

try:
from ..core.data import DaskInterface
except:
DF_INTERFACES.append(DaskInterface)


def get_df_data(element):
"""
Return element data as dataframe, avoiding casting if already
in dataframe format
"""
if element.interface in DF_INTERFACES:
return element.data
else:
return element.dframe()


class rolling(ElementOperation):
"""
Expand All @@ -23,6 +46,7 @@ class rolling(ElementOperation):

def _apply(self, element, key=None):
xdim = element.kdims[0].name
df = get_df_data(element)
df = df.rolling(window=self.p.rolling_window, center=self.p.center, on=xdim)
return element.clone(df.apply(self.p.function).reset_index())

Expand All @@ -46,7 +70,7 @@ class resample(ElementOperation):

def _apply(self, element, key=None):
xdim = element.kdims[0].name
df = element.dframe()
df = get_df_data(element)
df = df.resample(rule=self.p.rule, label=self.p.edge, on=xdim)
return element.clone(df.apply(self.p.function).reset_index())

Expand Down

0 comments on commit 838012d

Please sign in to comment.