Skip to content

Conversation

@siliataider
Copy link
Contributor

@siliataider siliataider commented Oct 24, 2025

This Pull request:

This PR introduces the first steps toward enabling UHI serialization for ROOT histograms (see scikit-hep/uhi#167).

It implements

  • _to_uhi_ for ROOT histograms: provides an Intermediate Representation of the histogram described by the UHI schema.
  • _from_uhi_ classmethod: converts from a UHI histogram to a ROOT histogram.

Minimal reproducer:

import json

import numpy as np
import uhi.io.json

import ROOT

# Create a histogram
h = ROOT.TH1D("h", "h", 10, -5, 5)
h[...] = np.arange(10)

# Serialize to JSON
ir = json.loads(json.dumps(h, default=uhi.io.json.default), object_hook=uhi.io.json.object_hook)

# Deserialize via constructor
h_loaded_ctor = ROOT.TH1D(ir)

# Deserialize via classmethod
h_loaded_clsmethod = ROOT.TH1D._from_uhi_(ir)

assert np.array_equal(h.values(), h_loaded_ctor.values()) and np.array_equal(h.values(), h_loaded_clsmethod.values())

@siliataider siliataider changed the title [Python][UHI] Start introducing UHI serialization [Draft][Python][UHI] Start introducing UHI serialization Oct 24, 2025
@siliataider siliataider self-assigned this Oct 24, 2025
@github-actions
Copy link

github-actions bot commented Oct 24, 2025

Test Results

    22 files      22 suites   3d 22h 52m 56s ⏱️
 3 792 tests  3 792 ✅ 0 💤 0 ❌
80 337 runs  80 337 ✅ 0 💤 0 ❌

Results for commit ac2177b.

♻️ This comment has been updated with latest results.

@siliataider siliataider force-pushed the UHI-indexing branch 2 times, most recently from 2fab875 to 3b60209 Compare December 3, 2025 12:28
@siliataider siliataider force-pushed the UHI-indexing branch 12 times, most recently from 559690c to 4442d53 Compare December 18, 2025 18:11
@siliataider siliataider marked this pull request as ready for review December 19, 2025 11:16
@siliataider siliataider changed the title [Draft][Python][UHI] Start introducing UHI serialization [Python][UHI] Start introducing UHI serialization Jan 5, 2026
Copy link
Member

@vepadulano vepadulano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, thanks! A couple of minor comments from my side. As a followup, we'll definitely want to add some docs to the UHI section and possibly a tutorial. That can come later of course, this is also a fresher UHI feature which I believe still needs discussing in general outside of ROOT.

@siliataider
Copy link
Contributor Author

Thanks for the review @vepadulano , and yes docs will come in a later PR

@siliataider siliataider requested a review from vepadulano January 8, 2026 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants