Skip to content

Commit

Permalink
Python2 fix when inferring intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Oct 10, 2018
1 parent b384416 commit 07d0322
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions holoviews/core/data/grid.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import absolute_import

import datetime as dt
from collections import OrderedDict, defaultdict, Iterable

try:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 07d0322

Please sign in to comment.