Skip to content

Commit

Permalink
Make operation_kwargs private to the Histogram class
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmmease committed Sep 3, 2019
1 parent b078a31 commit e36d295
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
17 changes: 2 additions & 15 deletions holoviews/element/chart.py
Expand Up @@ -182,27 +182,14 @@ def __init__(self, data, edges=None, **params):
elif isinstance(data, tuple) and len(data) == 2 and len(data[0])+1 == len(data[1]):
data = data[::-1]

self._operation_kwargs = params.pop('operation_kwargs', None)
self._operation_kwargs = params.pop('_operation_kwargs', None)

super(Histogram, self).__init__(data, **params)

@property
def operation_kwargs(self):
"""
If Histogram was generated by the holoviews.operation.histogram
operation, this property contains a dictionary of keyword-value
arguments that can be used with the histogram operation to regenerate
this histogram from the same input dataset.
If Histogram was created directly using the constructor, property
will be None.
"""
return self._operation_kwargs

def clone(self, *args, **kwargs):
return super(Histogram, self).clone(
*args,
operation_kwargs=copy.deepcopy(self.operation_kwargs),
_operation_kwargs=copy.deepcopy(self._operation_kwargs),
**kwargs
)

Expand Down
4 changes: 2 additions & 2 deletions holoviews/operation/element.py
Expand Up @@ -663,10 +663,10 @@ def _process(self, element, key=None):
# from the same data set, but we can also generate a histogram using
# a different dataset that will share the exact same bins.
exclusions = {'log', 'bin_range', 'num_bins'}
params['operation_kwargs'] = {
params['_operation_kwargs'] = {
k: v for k, v in self.p.items() if k not in exclusions
}
params['operation_kwargs']['bins'] = list(edges)
params['_operation_kwargs']['bins'] = list(edges)
return Histogram((edges, hist), kdims=[element.get_dimension(selected_dim)],
label=element.label, **params)

Expand Down
6 changes: 3 additions & 3 deletions holoviews/tests/operation/testoperation.py
Expand Up @@ -167,7 +167,7 @@ def test_histogram_operation_kwargs(self):

# Check operation kwargs for histogram generated with operation
self.assertEqual(
op_hist.operation_kwargs,
op_hist._operation_kwargs,
{'dimension': 'y',
'normed': False,
'dynamic': False,
Expand All @@ -176,7 +176,7 @@ def test_histogram_operation_kwargs(self):

# Test that operation_kwargs is preserved through clone
self.assertEqual(
op_hist.clone().operation_kwargs,
op_hist.clone()._operation_kwargs,
{'dimension': 'y',
'normed': False,
'dynamic': False,
Expand All @@ -185,7 +185,7 @@ def test_histogram_operation_kwargs(self):

# Check that operation kwargs is None for histogram generated directly
# from the Histogram constructor
self.assertIsNone(hist.operation_kwargs)
self.assertIsNone(hist._operation_kwargs)

@da_skip
def test_dataset_histogram_dask(self):
Expand Down

0 comments on commit e36d295

Please sign in to comment.