Skip to content

Commit d961ca6

Browse files
committed
Bags with different ranges are different types.
1 parent 135b316 commit d961ca6

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

histogrammar/primitives/bag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Bag(Factory, Container):
2626
2727
A bag is the appropriate data type for scatter plots: a container that collects raw values, maintaining multiplicity but not order. (A "bag" is also known as a "multiset.") Conceptually, it is a mapping from distinct raw values to the number of observations: when two instances of the same raw value are observed, one key is stored and their weights add.
2828
29-
Although the user-defined function may return scalar numbers, fixed-dimension vectors of numbers, or categorical strings, it may not mix types. Different Bag primitives in an analysis tree may collect different types.
29+
Although the user-defined function may return scalar numbers, fixed-dimension vectors of numbers, or categorical strings, it may not mix range types. For the purposes of Label and Index (which can only collect aggregators of a single type), bags with different ranges are different types.
3030
"""
3131

3232
@staticmethod

histogrammar/primitives/collection.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ def __init__(self, **pairs):
256256
contentType = list(pairs.values())[0].name
257257
if any(x.name != contentType for x in pairs.values()):
258258
raise ContainerException("all Label values must have the same type")
259+
if contentType == "Bag":
260+
rangeType = list(pairs.values())[0].range
261+
if any(x.range != rangeType for x in pairs.values()):
262+
raise ContainerException("all Label values must have the same type")
259263

260264
self.entries = 0.0
261265
self.pairs = pairs
@@ -631,6 +635,10 @@ def __init__(self, *values):
631635
contentType = values[0].name
632636
if any(x.name != contentType for x in values):
633637
raise ValueError("all Index values must have the same type")
638+
if contentType == "Bag":
639+
rangeType = values[0].range
640+
if any(x.range != rangeType for x in values):
641+
raise ValueError("all Index values must have the same type")
634642

635643
self.entries = 0.0
636644
self.values = values

0 commit comments

Comments
 (0)