Skip to content

[BUG] Hist.fill does not accept scalars for sample argument #646

Open
@nsmith-

Description

@nsmith-

Take for example:

import hist
import numpy as np
h = hist.Hist.new.Regular(10, 0, 1, name="x").WeightedMean()

I can fill with

h.fill(x=np.array([0.1, 0.1, 0.2]), sample=np.array([1, 2, 3]), weight=np.array([1, 2, 3]))
h.fill(x=0.3, sample=np.array([4]), weight=1.)

etc. but not

>>> h.fill(x=0.3, sample=4, weight=1.)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-11-0e663158df79> in <module>
----> 1 h.fill(x=0.3, sample=4, weight=1.)

/usr/local/lib/python3.9/site-packages/hist/basehist.py in fill(self, weight, sample, threads, *args, **kwargs)
    233
    234         total_data = tuple(args) + tuple(data)  # Python 2 can't unpack twice
--> 235         return super().fill(*total_data, weight=weight, sample=sample, threads=threads)
    236
    237     def sort(

/usr/local/lib/python3.9/site-packages/boost_histogram/_internal/hist.py in fill(self, weight, sample, threads, *args)
    431
    432         if threads is None or threads == 1:
--> 433             self._hist.fill(*args_ars, weight=weight_ars, sample=sample_ars)
    434             return self
    435

ValueError: Sample array must be 1D

Metadata

Metadata

Assignees

No one assigned

    Labels

    project ideaCould be a fellow project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions