Skip to content

Commit

Permalink
Small fixes for Dateset.closest method
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Mar 4, 2017
1 parent 9407a51 commit 1cd4a2f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions holoviews/core/data/__init__.py
Expand Up @@ -196,12 +196,14 @@ def closest(self, coords):
will return the closest actual sample coordinates.
"""
if self.ndims > 1:
NotImplementedError("Closest method currently only "
"implemented for 1D Elements")
raise NotImplementedError("Closest method currently only "
"implemented for 1D Elements")

xs = self.dimension_values(0)
if xs.dtype.kind in 'SO':
raise NotImplementedError("Closest only supported for numeric types")
idxs = [np.argmin(np.abs(xs-coord)) for coord in coords]
return [xs[idx] for idx in idxs] if len(coords) > 1 else xs[idxs[0]]
return [xs[idx] for idx in idxs]


def sort(self, by=[]):
Expand Down

0 comments on commit 1cd4a2f

Please sign in to comment.