Skip to content

Commit

Permalink
Merge pull request #992 from ioam/interface_nonzero
Browse files Browse the repository at this point in the history
Dataset types use __nonzero/bool__ method for truthiness
  • Loading branch information
jlstevens committed Nov 29, 2016
2 parents 3ba0b42 + 90d9050 commit 8c03983
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
4 changes: 4 additions & 0 deletions holoviews/core/data/__init__.py
Expand Up @@ -426,6 +426,10 @@ def __len__(self):
"""
return self.interface.length(self)

def __nonzero__(self):
return self.interface.nonzero(self)

__bool__ = __nonzero__

@property
def shape(self):
Expand Down
8 changes: 2 additions & 6 deletions holoviews/core/data/dask.py
Expand Up @@ -229,12 +229,8 @@ def dframe(cls, columns, dimensions):
return columns.data.compute()

@classmethod
def length(cls, dataset):
"""
Length of dask dataframe is unknown, always return 1
for performance, use shape to compute dataframe shape.
"""
return 1
def nonzero(cls, dataset):
return True



Expand Down
4 changes: 4 additions & 0 deletions holoviews/core/data/interface.py
Expand Up @@ -207,6 +207,10 @@ def shape(cls, dataset):
def length(cls, dataset):
return len(dataset.data)

@classmethod
def nonzero(cls, dataset):
return bool(cls.length(dataset))

@classmethod
def redim(cls, dataset, dimensions):
return dataset.data
2 changes: 1 addition & 1 deletion holoviews/core/dimension.py
Expand Up @@ -629,7 +629,7 @@ def _valid_dimensions(self, dimensions):
@property
def ddims(self):
"The list of deep dimensions"
if self._deep_indexable and len(self):
if self._deep_indexable and self:
return self.values()[0].dimensions()
else:
return []
Expand Down
6 changes: 0 additions & 6 deletions holoviews/element/chart.py
Expand Up @@ -309,12 +309,6 @@ class Points(Chart):

_min_dims = 2 # Minimum number of columns

def __iter__(self):
i = 0
while i < len(self):
yield tuple(self.data[i, ...])
i += 1



class VectorField(Points):
Expand Down

0 comments on commit 8c03983

Please sign in to comment.