Skip to content

Commit

Permalink
allow masking even though it is a weird case
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfast authored and philippjfr committed Aug 31, 2020
1 parent 2b06b54 commit 00afd3b
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions holoviews/core/data/ibis.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ def sort(cls, dataset, by=[], reverse=False):

@classmethod
def redim(cls, dataset, dimensions):
print(dimensions)
return dataset.data.mutate(
**{v.name: dataset.data[k] for k, v in dimensions.items()}
)
Expand Down Expand Up @@ -242,16 +241,23 @@ def isscalar(cls, dataset, dim):

@classmethod
def select(cls, dataset, selection_mask=None, **selection):
if selection_mask is not None:
return dataset.data.filter(selection_mask)

selection_mask = cls.select_mask(dataset, selection)
if selection_mask is None:
selection_mask = cls.select_mask(dataset, selection)
indexed = cls.indexed(dataset, selection)
data = (
dataset.data
if selection_mask is None
else dataset.data.filter(selection_mask)
)
data = dataset.data

if selection_mask is not None:
if isinstance(selection_mask, numpy.ndarray):
data = cls._index_ibis_table(data)
if selection_mask.dtype == numpy.dtype("bool"):
selection_mask = numpy.where(selection_mask)[0]
data = data.filter(
data["hv_row_id__"].isin(list(map(int, selection_mask)))
).drop(["hv_row_id__"])
else:
data = data.filter(selection_mask)

if indexed and data.count().execute() == 1 and len(dataset.vdims) == 1:
return data[dataset.vdims[0].name].execute().iloc[0]
return data
Expand Down Expand Up @@ -283,6 +289,8 @@ def select_mask(cls, dataset, selection):
predicates.append(condition)
elif callable(object):
predicates.append(object(column))
elif isinstance(object, ibis.Expr):
predicates.append(object)
else:
predicates.append(column == object)
return predicates
Expand Down

0 comments on commit 00afd3b

Please sign in to comment.