Skip to content

Writing profiles with storage=WeightedMean() #1533

@wiso

Description

@wiso

This is similar to #1531 about the problem writing profiles. The following code is run on top of uproot 5.6.8 patched with the present proposed fix in #1532 and hist 2.9.0

import uproot
import hist

h = hist.Hist(
    hist.axis.IntCategory([10, 20, 30]),
    storage=hist.storage.WeightedMean())

with uproot.recreate("test.root") as fout:
    fout['h'] = h
/home/turra/micromamba/envs/mamba-python3.12/lib/python3.12/site-packages/uproot/writing/identify.py:272: FutureWarning: .metadata was not set, returning None instead of Attribute error, boost-histogram 1.7+ will error.
  if obj.metadata is not None and "fSumw2" in obj.metadata.keys():
Traceback (most recent call last):
  File "/home/turra/test-histo.py", line 9, in <module>
    fout['h'] = h
    ~~~~^^^^^
  File "/home/turra/micromamba/envs/mamba-python3.12/lib/python3.12/site-packages/uproot/writing/writable.py", line 986, in __setitem__
    self.update({where: what})
  File "/home/turra/micromamba/envs/mamba-python3.12/lib/python3.12/site-packages/uproot/writing/writable.py", line 1598, in update
    uproot.writing.identify.add_to_directory(v, name, directory, streamers)
  File "/home/turra/micromamba/envs/mamba-python3.12/lib/python3.12/site-packages/uproot/writing/identify.py", line 79, in add_to_directory
    writable = to_writable(obj)
               ^^^^^^^^^^^^^^^^
  File "/home/turra/micromamba/envs/mamba-python3.12/lib/python3.12/site-packages/uproot/writing/identify.py", line 283, in to_writable
    fSumw2 = obj.view()["count"]
             ~~~~~~~~~~^^^^^^^^^
  File "/home/turra/micromamba/envs/mamba-python3.12/lib/python3.12/site-packages/boost_histogram/view.py", line 20, in __getitem__
    sliced = super().__getitem__(ind)
             ^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: no field of name count

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug (unverified)The problem described would be a bug, but needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions