Skip to content

Commit

Permalink
Simplified Interface.applies and types
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Oct 7, 2018
1 parent 08e26ff commit 796b209
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions holoviews/core/data/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class Interface(param.Parameterized):

datatype = None

types = ()

# Denotes whether the interface expects gridded data
gridded = False

Expand All @@ -113,9 +115,13 @@ def loaded(cls):
@classmethod
def applies(cls, obj):
"""
Whether the Interface can operate on the supplied data object.
Indicates whether the interface is designed specifically to
handle the supplied object's type. By default simply checks
if the object is one of the types declared on the class,
however if the type is expensive to import at load time the
method may be overridden.
"""
return False
return (isinstance(obj, t) for t in cls.types)

@classmethod
def register(cls, interface):
Expand Down Expand Up @@ -190,7 +196,7 @@ def initialize(cls, eltype, data, kdims, vdims, datatype=None):
# Set interface priority order
prioritized = [cls.interfaces[p] for p in datatype
if p in cls.interfaces]
head = [intfc for intfc in prioritized if (intfc.types != () and type(data) in intfc.types) or intfc.applies(data)]
head = [intfc for intfc in prioritized if intfc.applies(data)]
if head:
# Prioritize interfaces which have matching types
prioritized = head + [el for el in prioritized if el != head[0]]
Expand Down

0 comments on commit 796b209

Please sign in to comment.