Simplified DynamicMap.collate
@@ -811,50 +811,24 @@ class DynamicMap(HoloMap):
def collate(self):
"""
- Collation allows collapsing DynamicMaps with invalid nesting
+ Collation allows reorganizing DynamicMaps with invalid nesting
hierarchies. This is particularly useful when defining
DynamicMaps returning an (Nd)Layout or GridSpace
- type. Collating will split the DynamicMap into of individual
- DynamicMaps. Note that the composite object has to be of
- consistent length and types for this to work
- correctly. Associating streams with specific viewables in the
- returned container declare a stream_mapping on the DynamicMap
- Callable during instantiation.
+ types. Collating will split the DynamicMap into individual
+ DynamicMaps for each item in the container. Note that the
+ composite object has to be of consistent length and types for
+ this to work correctly.
"""
# Initialize
if self.last is not None:
pass
else:
- self[self._initial_key()]
-
- if isinstance(self.last, HoloMap):
- # Get nested kdims and streams
- streams = list(self.streams)
- if isinstance(self.last, DynamicMap):
- dimensions = [d(values=self.last.dimension_values(d.name))
- for d in self.last.kdims]
- streams += self.last.streams
- stream_kwargs = set()
- for stream in streams:
- contents = set(stream.contents())
- if stream_kwargs & contents:
- raise KeyError('Cannot collate DynamicMaps with clashing '
- 'stream parameters.')
- else:
- dimensions = self.last.kdims
- kdims = self.kdims+dimensions
+ self.clone()[self._initial_key()]
- # Define callback
- def collation_cb(*args, **kwargs):
- return self[args[:self.ndims]][args[self.ndims:]]
- callback = Callable(collation_cb, inputs=[self])
+ if not isinstance(self.last, (Layout, NdLayout, GridSpace)):
+ return self
- return self.clone(shared_data=False, callback=callback,
- kdims=kdims, streams=streams)
- elif isinstance(self.last, (Layout, NdLayout, GridSpace)):
- # Expand Layout/NdLayout
- from ..util import Dynamic
- new_item = self.last.clone(shared_data=False)
+ container = self.last.clone(shared_data=False)
# Get stream mapping from callback
remapped_streams = []
@@ -879,8 +853,8 @@ class DynamicMap(HoloMap):
# Define collation callback
def collation_cb(*args, **kwargs):
- return self[args][kwargs['collation_key']]
- callback = Callable(partial(collation_cb, collation_key=k),
+ return self[args][kwargs['selection_key']]
+ callback = Callable(partial(collation_cb, selection_key=k),
inputs=[self])
vdmap = self.clone(callback=callback, shared_data=False,
streams=vstreams)
@@ -889,7 +863,7 @@ class DynamicMap(HoloMap):
for stream in vstreams:
if stream.source is self:
stream.source = vdmap
- new_item[k] = vdmap
+ container[k] = vdmap
unmapped_streams = [repr(stream) for stream in self.streams
if (stream.source is self) and
@@ -902,10 +876,7 @@ class DynamicMap(HoloMap):
'which item in the (Nd)Layout to link it to was found:\n%s'
% ', '.join(unmapped_streams)
)
- return new_item
- else:
- self.warning('DynamicMap does not need to be collated.')
- return dmap
+ return container
def groupby(self, dimensions=None, container_type=None, group_type=None, **kwargs):
