Skip to content

Commit b1b384c

Browse files
committed
[Python][UHI] Fix histogram kind assignment
1 parent e42fe7c commit b1b384c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

bindings/pyroot/pythonizations/python/ROOT/_pythonization/_uhi.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,10 @@ def _axes(self) -> Tuple[Union[PlottableAxisContinuous, PlottableAxisDiscrete],
483483

484484

485485
def _kind(self) -> Kind:
486-
return Kind.COUNT if not _hasWeights(self) else Kind.MEAN
486+
# TProfile -> MEAN, everything else -> COUNT
487+
if self.__class__.__name__.startswith("TProfile"):
488+
return Kind.MEAN
489+
return Kind.COUNT
487490

488491

489492
def _values_default(self) -> np.typing.NDArray[Any]: # noqa: F821

bindings/pyroot/pythonizations/test/uhi_indexing.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,5 +357,22 @@ def test_uhi_projection_preserves_content(self):
357357
assert np.allclose(uhi_values, ref_values)
358358

359359

360+
class TestHistogramKind:
361+
def test_histogram_kind_no_weights(self):
362+
h = ROOT.TH1D("h", "h", 100, -10, 10)
363+
h.Fill(5)
364+
assert h.kind == "COUNT"
365+
366+
def test_histogram_kind_with_weights(self):
367+
h_weighted = ROOT.TH1D("h_weighted", "h_weighted", 100, -10, 10)
368+
h_weighted.Fill(5, 2.0)
369+
assert h_weighted.kind == "COUNT"
370+
371+
def test_profile_histogram_kind(self):
372+
h_profile = ROOT.TProfile("h_profile", "h_profile", 100, -10, 10)
373+
h_profile.Fill(5, 3.0)
374+
assert h_profile.kind == "MEAN"
375+
376+
360377
if __name__ == "__main__":
361378
raise SystemExit(pytest.main(args=[__file__]))

0 commit comments

Comments
 (0)