From 05ba546be377f4721d94b1bf292df85d795d2963 Mon Sep 17 00:00:00 2001 From: Jay Gohil Date: Wed, 13 Jul 2022 23:40:03 -0400 Subject: [PATCH 1/3] Added private boolean-based compare function --- src/boost_histogram/_internal/utils.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/boost_histogram/_internal/utils.py b/src/boost_histogram/_internal/utils.py index e7a2e2635..4e5ff14ac 100644 --- a/src/boost_histogram/_internal/utils.py +++ b/src/boost_histogram/_internal/utils.py @@ -200,3 +200,16 @@ def zip_strict(*args: Any) -> Iterator[Tuple[Any, ...]]: if val is marker: raise ValueError("zip() arguments are not the same length") yield each + +def compare(self: "Histogram", hist2: "Histogram", **kwargs) -> str: + if not np.allclose(self.view().shape, hist2.view().shape, **kwargs): + return False + if not np.allclose(self.view(), hist2.view(), **kwargs): + return False + if not np.allclose(self.to_numpy()[1], hist2.to_numpy()[1], **kwargs): + return False + if self._storage_type != hist2._storage_type: + return False + if list(self.axes) != list(hist2.axes): + return False + return True From 2730781948b8dd15ada62950e32c2e64cd5223ef Mon Sep 17 00:00:00 2001 From: Jay Gohil Date: Thu, 14 Jul 2022 23:48:55 -0400 Subject: [PATCH 2/3] Added assert based test compare function for future internal use --- src/boost_histogram/_internal/utils.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/boost_histogram/_internal/utils.py b/src/boost_histogram/_internal/utils.py index 4e5ff14ac..17ca27354 100644 --- a/src/boost_histogram/_internal/utils.py +++ b/src/boost_histogram/_internal/utils.py @@ -213,3 +213,17 @@ def compare(self: "Histogram", hist2: "Histogram", **kwargs) -> str: if list(self.axes) != list(hist2.axes): return False return True + +""" +def test_compare(self: "Histogram", hist2: "Histogram", **kwargs) -> str: + if not np.allclose(self.view().shape, hist2.view().shape, **kwargs): + assert self.view().shape == hist2.view().shape, 'The dimensions are not similar.' + if not np.allclose(self.view(), hist2.view(), **kwargs): + assert self.view() == hist2.view(), 'The contents are not similar.' + if not np.allclose(self.to_numpy()[1], hist2.to_numpy()[1], **kwargs): + assert self.to_numpy()[1] == hist2.to_numpy()[1], 'The edges are not similar.' + if self._storage_type != hist2._storage_type: + assert str(self._storage_type).split('.')[-1][:-2] == str(hist2._storage_type).split('.')[-1][:-2], 'The storages are not similar.' + if list(self.axes) != list(hist2.axes): + assert list(self.axes) == list(hist2.axes), 'The edges are not similar' +""" From 080b45ad0ceed93e3303f4e307e5b9720bdffe19 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 15 Aug 2022 21:02:01 +0000 Subject: [PATCH 3/3] style: pre-commit fixes --- src/boost_histogram/_internal/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/boost_histogram/_internal/utils.py b/src/boost_histogram/_internal/utils.py index 17ca27354..2701aff55 100644 --- a/src/boost_histogram/_internal/utils.py +++ b/src/boost_histogram/_internal/utils.py @@ -201,6 +201,7 @@ def zip_strict(*args: Any) -> Iterator[Tuple[Any, ...]]: raise ValueError("zip() arguments are not the same length") yield each + def compare(self: "Histogram", hist2: "Histogram", **kwargs) -> str: if not np.allclose(self.view().shape, hist2.view().shape, **kwargs): return False @@ -214,6 +215,7 @@ def compare(self: "Histogram", hist2: "Histogram", **kwargs) -> str: return False return True + """ def test_compare(self: "Histogram", hist2: "Histogram", **kwargs) -> str: if not np.allclose(self.view().shape, hist2.view().shape, **kwargs):