Skip to content

Commit

Permalink
Add Operation._propagate_dataset class flag to control whether to aut…
Browse files Browse the repository at this point in the history
…omatically

propagate dataset through operation
  • Loading branch information
jonmmease committed Dec 19, 2019
1 parent c5adc79 commit c65395b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
7 changes: 6 additions & 1 deletion holoviews/core/operation.py
Expand Up @@ -70,6 +70,10 @@ class Operation(param.ParameterizedFunction):
_postprocess_hooks = []
_allow_extra_keywords=False

# Flag indicating whether to automatically propagate the .dataset property from
# the input of the operation to the result
_propagate_dataset = True

@classmethod
def search(cls, element, pattern):
"""
Expand Down Expand Up @@ -126,7 +130,8 @@ def _apply(self, element, key=None):
for hook in self._postprocess_hooks:
ret = hook(self, ret, **kwargs)

if isinstance(ret, Dataset) and isinstance(element, Dataset):
if (self._propagate_dataset and
isinstance(ret, Dataset) and isinstance(element, Dataset)):
ret._dataset = element.dataset.clone()
ret._pipeline = element_pipeline.instance(
operations=element_pipeline.operations + [
Expand Down
20 changes: 19 additions & 1 deletion holoviews/tests/core/testdatasetproperty.py
Expand Up @@ -11,7 +11,7 @@
from holoviews import Dataset, Curve, Dimension, Scatter, Distribution
from holoviews.core import Apply, Redim
from holoviews.element.comparison import ComparisonTestCase
from holoviews.operation import histogram
from holoviews.operation import histogram, function

try:
from holoviews.operation.datashader import dynspread, datashade, rasterize
Expand Down Expand Up @@ -826,3 +826,21 @@ def test_redim_curve(self):
self.assertEqual(
curve.pipeline(self.ds2), curve2
)


class OperationTestCase(DatasetPropertyTestCase):
def test_propagate_dataset(self):
op = function.instance(
fn=lambda ds: ds.iloc[:5].clone(dataset=None, pipeline=None)
)
new_ds = op(self.ds)
self.assertEqual(new_ds.dataset, self.ds)

def test_do_not_propagate_dataset(self):
op = function.instance(
fn=lambda ds: ds.iloc[:5].clone(dataset=None, pipeline=None)
)
# Disable dataset propagation
op._propagate_dataset = False
new_ds = op(self.ds)
self.assertEqual(new_ds.dataset, new_ds)

0 comments on commit c65395b

Please sign in to comment.