Skip to content

Commit

Permalink
Fixed datetime casting on dask dataframe (#3460)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Feb 4, 2019
1 parent 3427e10 commit 99c865d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions holoviews/operation/datashader.py
Expand Up @@ -329,8 +329,8 @@ def get_agg_data(cls, obj, category=None):
df = df.copy()

for d in (x, y):
vals = df[d.name].values
if not is_dask and len(vals) and isinstance(vals[0], cftime_types):
vals = df[d.name]
if not is_dask and len(vals) and isinstance(vals.values[0], cftime_types):
vals = cftime_to_timestamp(vals, 'ns')
elif df[d.name].dtype.kind == 'M':
vals = vals.astype('datetime64[ns]')
Expand Down
19 changes: 18 additions & 1 deletion holoviews/tests/operation/testdatashader.py
Expand Up @@ -4,10 +4,11 @@
from holoviews import (Dimension, Curve, Points, Image, Dataset, RGB, Path,
Graph, TriMesh, QuadMesh, NdOverlay, Contours)
from holoviews.element.comparison import ComparisonTestCase
from holoviews.core.util import pd

try:
import datashader as ds
import dask.dataframe as dd
from holoviews.core.util import pd
from holoviews.operation.datashader import (
aggregate, regrid, ds_version, stack, directly_connect_edges,
shade, rasterize
Expand Down Expand Up @@ -93,6 +94,22 @@ def test_aggregate_curve_datetimes(self):
datatype=['xarray'], bounds=bounds, vdims='Count')
self.assertEqual(img, expected)

def test_aggregate_curve_datetimes_dask(self):
df = pd.DataFrame(
data=np.arange(1000), columns=['a'],
index=pd.date_range('2019-01-01', freq='1T', periods=1000),
)
ddf = dd.from_pandas(df, npartitions=4)
curve = Curve(ddf, kdims=['index'], vdims=['a'])
img = aggregate(curve, width=2, height=3, dynamic=False)
bounds = (np.datetime64('2019-01-01T00:00:00.000000'), 0.0,
np.datetime64('2019-01-01T16:39:00.000000'), 999.0)
dates = [np.datetime64('2019-01-01T04:09:45.000000000'),
np.datetime64('2019-01-01T12:29:15.000000000')]
expected = Image((dates, [166.5, 499.5, 832.5], [[333, 0], [167, 166], [0, 334]]),
['index', 'a'], 'Count', datatype=['xarray'], bounds=bounds)
self.assertEqual(img, expected)

def test_aggregate_curve_datetimes_microsecond_timebase(self):
dates = pd.date_range(start="2016-01-01", end="2016-01-03", freq='1D')
xstart = np.datetime64('2015-12-31T23:59:59.723518000', 'us')
Expand Down

0 comments on commit 99c865d

Please sign in to comment.