diff --git a/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_uhi.py b/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_uhi.py index 3cb80d322a17f..23d11a6f3e897 100644 --- a/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_uhi.py +++ b/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_uhi.py @@ -379,20 +379,9 @@ def _setitem(self, index, value): _slice_set(self, uhi_index, index, value) -def _eq(self, other): - import numpy as np - - return ( - isinstance(other, type(self)) - and _shape(self) == _shape(other) - and np.array_equal(_values_default(self), _values_default(other)) - ) - - def _add_indexing_features(klass: Any) -> None: klass.__getitem__ = _getitem klass.__setitem__ = _setitem - klass.__eq__ = _eq """ @@ -559,11 +548,12 @@ def _get_sum_of_weights_squared(self) -> np.typing.NDArray[Any]: # noqa: F821 import numpy as np shape = _shape(self, include_flow_bins=False) - return np.frombuffer( + sumw2_arr = np.frombuffer( self.GetSumw2().GetArray(), dtype=self.GetSumw2().GetArray().typecode, count=self.GetSumw2().GetSize(), - ).reshape(shape, order="F")[tuple([slice(1, -1)] * len(shape))] + ) + return sumw2_arr[tuple([slice(1, -1)] * len(shape))].reshape(shape, order="F") if sumw2_arr.size > 0 else sumw2_arr values_func_dict: dict[str, Callable] = { diff --git a/bindings/pyroot/pythonizations/test/uhi_indexing.py b/bindings/pyroot/pythonizations/test/uhi_indexing.py index 2a98d3c7f5c77..8ecba4b7d9026 100644 --- a/bindings/pyroot/pythonizations/test/uhi_indexing.py +++ b/bindings/pyroot/pythonizations/test/uhi_indexing.py @@ -315,6 +315,19 @@ def test_statistics_slice(self, hist_setup): assert hist_setup.GetStdDev() == pytest.approx(sliced_hist.GetStdDev(), rel=10e-5) assert hist_setup.GetMean() == pytest.approx(sliced_hist.GetMean(), rel=10e-5) + def test_equality(self, hist_setup): + if _special_setting(hist_setup): + pytest.skip("Setting cannot be tested here") + + hist_copy_ptr = hist_setup + assert hist_setup == hist_copy_ptr + + hist_copy = hist_setup.Clone() + assert hist_setup != hist_copy + + hist_full_slice = hist_setup[...] + assert hist_setup != hist_full_slice + if __name__ == "__main__": pytest.main(args=[__file__])