Skip to content

Commit

Permalink
Iris interface groupby now uses fuzzy matching of floats
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Apr 27, 2016
1 parent 4c260b6 commit b067da2
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions holoviews/core/data/iris.py
Expand Up @@ -2,6 +2,7 @@

import datetime
from itertools import product
from functools import partial
import unittest

import iris
Expand Down Expand Up @@ -54,6 +55,12 @@ def sort_coords(coord):
return (order.get(axis, 0), coord and coord.name())


def isclose(cell, value=0, precision=1e-5):
"""
Matches two float values with a specific precision
"""
return value-precision < cell < value+precision


class CubeInterface(GridInterface):
"""
Expand Down Expand Up @@ -166,7 +173,10 @@ def groupby(cls, dataset, dims, container_type=HoloMap, group_type=None, **kwarg

if dynamic:
def load_subset(*args):
args = (partial(isclose, value=arg) if isinstance(arg, float) else arg
for arg in args)
constraint = iris.Constraint(**dict(zip(constraints, args)))
extracted = dataset.data.extract(constraint)
return dataset.clone(dataset.data.extract(constraint),
new_type=group_type,
**dict(kwargs, kdims=slice_dims))
Expand Down

0 comments on commit b067da2

Please sign in to comment.