def ed(entries, contentType, binsAsDict=None, **bins):
"""Create a Categorize that is only capable of being added.
Parameters:
entries (float): the number of entries.
contentType (str): the value's sub-aggregator type (must be provided to determine type for the case when `bins` is empty).
bins (dict from str to :doc:`Container <histogrammar.defs.Container>`): the non-empty bin categories and their values.
"""
if not isinstance(entries, numbers.Real) and entries not in ("nan", "inf", "-inf"):
raise TypeError("entries ({0}) must be a number".format(entries))
if not isinstance(contentType, basestring):
raise TypeError("contentType ({0}) must be a string".format(contentType))
if not all(isinstance(k, basestring) and isinstance(v, Container) for k, v in bins.items()):
raise TypeError("bins ({0}) must be a dict from strings to Containers".format(bins))
if entries < 0.0:
raise ValueError("entries ({0}) cannot be negative".format(entries))
out = Categorize(None, None)
out.entries = float(entries)
if binsAsDict is None:
out.bins = {}
else:
out.bins = binsAsDict
out.bins.update(bins)
out.contentType = contentType
return out.specialize()
评论列表
文章目录