From 07d032220d712ea85284952b33d948e41fcc39da Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Wed, 10 Oct 2018 22:50:04 +0100 Subject: [PATCH] Python2 fix when inferring intervals --- holoviews/core/data/grid.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/holoviews/core/data/grid.py b/holoviews/core/data/grid.py index 9cbce3278f..5f1f30eafe 100644 --- a/holoviews/core/data/grid.py +++ b/holoviews/core/data/grid.py @@ -1,5 +1,6 @@ from __future__ import absolute_import +import datetime as dt from collections import OrderedDict, defaultdict, Iterable try: @@ -188,6 +189,9 @@ def _infer_interval_breaks(cls, coord, axis=0): [ 2.5, 3.5, 4.5]]) """ coord = np.asarray(coord) + if sys.version_info.major == 2 and len(coord) and isinstance(coord[0], (dt.datetime, dt.date)): + # np.diff does not work on datetimes in python 2 + coord = coord.astype('datetime64') deltas = 0.5 * np.diff(coord, axis=axis) first = np.take(coord, [0], axis=axis) - np.take(deltas, [0], axis=axis) last = np.take(coord, [-1], axis=axis) + np.take(deltas, [-1], axis=axis)