From 485d38422e8d543513499fc8b0c4c21e6f6796aa Mon Sep 17 00:00:00 2001 From: Alexander Puck Neuwirth Date: Sun, 13 Oct 2024 11:58:25 +0200 Subject: [PATCH] Test to/from_string Closes: #10 --- src/babyyoda/grogu/histo1d_v2.py | 46 ++++--- src/babyyoda/grogu/histo1d_v3.py | 31 +++-- src/babyyoda/grogu/histo2d_v2.py | 24 ++-- src/babyyoda/grogu/histo2d_v3.py | 31 +++-- src/babyyoda/grogu/read.py | 14 +- src/babyyoda/test.py | 2 +- tests/babyyoda/test_histo1d.py | 20 +-- tests/babyyoda/uhi/test_by_histo1d_slicing.py | 18 +-- tests/grogu/test_gg_string.py | 129 ++++++++++++++++++ tests/grogu/uhi/test_gg_histo1d_slicing.py | 18 +-- tests/yoda/test_yoda_vs_grogu.py | 4 +- 11 files changed, 251 insertions(+), 86 deletions(-) diff --git a/src/babyyoda/grogu/histo1d_v2.py b/src/babyyoda/grogu/histo1d_v2.py index ac00829..669d725 100644 --- a/src/babyyoda/grogu/histo1d_v2.py +++ b/src/babyyoda/grogu/histo1d_v2.py @@ -17,6 +17,11 @@ class Bin: d_sumwx2: float = 0.0 d_numentries: float = 0.0 + def __post_init__(self): + assert ( + self.d_xmin is None or self.d_xmax is None or self.d_xmin < self.d_xmax + ) + ######################################################## # YODA compatibilty code ######################################################## @@ -129,17 +134,17 @@ def xVariance(self): def numEntries(self): return self.d_numentries - def __eq__(self, other): - return ( - isinstance(other, GROGU_HISTO1D_V2.Bin) - and self.d_xmin == other.d_xmin - and self.d_xmax == other.d_xmax - and self.d_sumw == other.d_sumw - and self.d_sumw2 == other.d_sumw2 - and self.d_sumwx == other.d_sumwx - and self.d_sumwx2 == other.d_sumwx2 - and self.d_numentries == other.d_numentries - ) + # def __eq__(self, other): + # return ( + # isinstance(other, GROGU_HISTO1D_V2.Bin) + # and self.d_xmin == other.d_xmin + # and self.d_xmax == other.d_xmax + # and self.d_sumw == other.d_sumw + # and self.d_sumw2 == other.d_sumw2 + # and self.d_sumwx == other.d_sumwx + # and self.d_sumwx2 == other.d_sumwx2 + # and self.d_numentries == other.d_numentries + # ) def __add__(self, other): assert isinstance(other, GROGU_HISTO1D_V2.Bin) @@ -302,8 +307,11 @@ def to_string(histo) -> str: return f"{header}{stats}{underflow}\n{overflow}\n{legend}{bin_data}\n{footer}" @classmethod - def from_string(cls, file_content: str, key: str = "") -> "GROGU_HISTO1D_V2": + def from_string(cls, file_content: str) -> "GROGU_HISTO1D_V2": lines = file_content.strip().splitlines() + key = "" + if find := re.search(r"BEGIN YODA_HISTO1D_V2 (\S+)", lines[0]): + key = find.group(1) # Extract metadata (path, title) path = "" @@ -322,7 +330,11 @@ def from_string(cls, file_content: str, key: str = "") -> "GROGU_HISTO1D_V2": data_section_started = False for line in lines: - if line.startswith("#"): + if line.startswith("BEGIN YODA_HISTO1D_V2"): + continue + if line.startswith("END YODA_HISTO1D_V2"): + break + if line.startswith("#") or line.isspace(): continue if line.startswith("---"): data_section_started = True @@ -332,18 +344,18 @@ def from_string(cls, file_content: str, key: str = "") -> "GROGU_HISTO1D_V2": values = re.split(r"\s+", line.strip()) if values[0] == "Underflow": - underflow = GROGU_HISTO1D_V2.Bin.from_string(line) + underflow = cls.Bin.from_string(line) elif values[0] == "Overflow": - overflow = GROGU_HISTO1D_V2.Bin.from_string(line) + overflow = cls.Bin.from_string(line) elif values[0] == "Total": # ignore for now pass else: # Regular bin - bins.append(GROGU_HISTO1D_V2.Bin.from_string(line)) + bins.append(cls.Bin.from_string(line)) # Create and return the YODA_HISTO1D_V2 object - return GROGU_HISTO1D_V2( + return cls( d_key=key, d_path=path, d_title=title, diff --git a/src/babyyoda/grogu/histo1d_v3.py b/src/babyyoda/grogu/histo1d_v3.py index cf17ae3..4912fd1 100644 --- a/src/babyyoda/grogu/histo1d_v3.py +++ b/src/babyyoda/grogu/histo1d_v3.py @@ -155,7 +155,9 @@ def from_string(cls, string: str) -> "GROGU_HISTO1D_V3.Bin": def __post_init__(self): self.d_type = "Histo1D" # one more edge than bins, subtract 2 for underflow and overflow - assert len(self.d_edges) == len(self.d_bins) + 1 - 2 + assert ( + len(self.d_edges) == len(self.d_bins) + 1 - 2 + ), f"{len(self.d_edges)} != {len(self.d_bins)} + 1 - 2" ############################################ # YODA compatibilty code @@ -238,8 +240,11 @@ def rebinXTo(self, edges: List[float]): assert len(self.d_bins) == len(self.xEdges()) - 1 + 2 @classmethod - def from_string(cls, file_content: str, key: str = "") -> "GROGU_HISTO1D_V3": + def from_string(cls, file_content: str) -> "GROGU_HISTO1D_V3": lines = file_content.strip().splitlines() + key = "" + if find := re.search(r"BEGIN YODA_HISTO1D_V3 (\S+)", lines[0]): + key = find.group(1) # Extract metadata (path, title) path = "" @@ -258,7 +263,11 @@ def from_string(cls, file_content: str, key: str = "") -> "GROGU_HISTO1D_V3": data_section_started = False for line in lines: - if line.startswith("#"): + if line.startswith("BEGIN YODA_HISTO1D_V3"): + continue + if line.startswith("END YODA_HISTO1D_V3"): + break + if line.startswith("#") or line.isspace(): continue if line.startswith("---"): data_section_started = True @@ -267,17 +276,15 @@ def from_string(cls, file_content: str, key: str = "") -> "GROGU_HISTO1D_V3": continue if line.startswith("Edges"): - content = re.findall(r"\[(.*?)\]", line) - numbers_as_strings = re.findall( - r"[-+]?\d*\.\d+e[+-]?\d+|\d+", content[0] - ) - edges = [float(i) for i in numbers_as_strings] + content = re.findall(r"\[(.*?)\]", line)[0] + values = re.split(r"\s+", content.replace(",", "")) + edges = [float(i) for i in values] continue - bins.append(GROGU_HISTO1D_V3.Bin.from_string(line)) + bins.append(cls.Bin.from_string(line)) # Create and return the YODA_HISTO1D_V2 object - return GROGU_HISTO1D_V3( + return cls( d_key=key, d_path=path, d_title=title, @@ -303,8 +310,8 @@ def to_string(self): edges = f"Edges(A1): [{', '.join(str(e) for e in self.d_edges)}]\n" # Add the bin data - bin_data = "\n".join(GROGU_HISTO1D_V3.Bin.to_string(b) for b in self.bins()) + bin_data = "\n".join(GROGU_HISTO1D_V3.Bin.to_string(b) for b in self.bins(True)) footer = "END YODA_HISTO1D_V3\n" - return f"{header}{stats}{edges}\n\n# sumW\t sumW2\t sumW(A1)\t sumW2(A1)\t numEntries\n{bin_data}\n{footer}" + return f"{header}{stats}{edges}# sumW\t sumW2\t sumW(A1)\t sumW2(A1)\t numEntries\n{bin_data}\n{footer}" diff --git a/src/babyyoda/grogu/histo2d_v2.py b/src/babyyoda/grogu/histo2d_v2.py index 92626f6..dca6bae 100644 --- a/src/babyyoda/grogu/histo2d_v2.py +++ b/src/babyyoda/grogu/histo2d_v2.py @@ -205,14 +205,18 @@ def to_string(self) -> str: legend = "# xlow\t xhigh\t ylow\t yhigh\t sumw\t sumw2\t sumwx\t sumwx2\t sumwy\t sumwy2\t sumwxy\t numEntries\n" bin_data = "\n".join(b.to_string() for b in self.d_bins) - footer = "END YODA_HISTO2D_V2\n" + footer = "\nEND YODA_HISTO2D_V2\n" return f"{header}{stats}{legend}{bin_data}{footer}" @classmethod - def from_string(cls, file_content: str, name: str = "") -> "GROGU_HISTO2D_V2": + def from_string(cls, file_content: str) -> "GROGU_HISTO2D_V2": lines = file_content.strip().splitlines() + key = "" + if find := re.search(r"BEGIN YODA_HISTO2D_V2 (\S+)", lines[0]): + key = find.group(1) + # Extract metadata (path, title) path = "" title = "" @@ -229,7 +233,11 @@ def from_string(cls, file_content: str, name: str = "") -> "GROGU_HISTO2D_V2": data_section_started = False for line in lines: - if line.startswith("#"): + if line.startswith("BEGIN YODA_HISTO2D_V2"): + continue + if line.startswith("END YODA_HISTO2D_V2"): + break + if line.startswith("#") or line.isspace(): continue if line.startswith("---"): data_section_started = True @@ -239,7 +247,7 @@ def from_string(cls, file_content: str, name: str = "") -> "GROGU_HISTO2D_V2": values = re.split(r"\s+", line.strip()) if values[0] == "Underflow": - underflow = GROGU_HISTO2D_V2.Bin( + underflow = cls.Bin( None, None, None, @@ -254,7 +262,7 @@ def from_string(cls, file_content: str, name: str = "") -> "GROGU_HISTO2D_V2": float(values[9]), ) elif values[0] == "Overflow": - overflow = GROGU_HISTO2D_V2.Bin( + overflow = cls.Bin( None, None, None, @@ -286,7 +294,7 @@ def from_string(cls, file_content: str, name: str = "") -> "GROGU_HISTO2D_V2": numEntries, ) = map(float, values) bins.append( - GROGU_HISTO2D_V2.Bin( + cls.Bin( xlow, xhigh, ylow, @@ -302,8 +310,8 @@ def from_string(cls, file_content: str, name: str = "") -> "GROGU_HISTO2D_V2": ) ) - return GROGU_HISTO2D_V2( - d_key=name, + return cls( + d_key=key, d_path=path, d_title=title, d_bins=bins, diff --git a/src/babyyoda/grogu/histo2d_v3.py b/src/babyyoda/grogu/histo2d_v3.py index c59b4c1..d64db80 100644 --- a/src/babyyoda/grogu/histo2d_v3.py +++ b/src/babyyoda/grogu/histo2d_v3.py @@ -177,19 +177,24 @@ def to_string(self) -> str: # f"# Mean: {self.mean()}\n" # f"# Area: {self.area()}\n" # ) + edges = "" + for i, edg in enumerate(self.d_edges): + edges += f"Edges(A{i+1}): [{', '.join(str(e) for e in edg )}]\n" legend = ( "# sumw\t sumw2\t sumwx\t sumwx2\t sumwy\t sumwy2\t sumwxy\t numEntries\n" ) bin_data = "\n".join(b.to_string() for b in self.d_bins) - footer = "END YODA_HISTO2D_V3\n" + footer = "\nEND YODA_HISTO2D_V3\n" - return f"{header}{stats}{legend}{bin_data}{footer}" + return f"{header}{stats}{edges}{legend}{bin_data}{footer}" @classmethod - def from_string(cls, file_content: str, key: str = "") -> "GROGU_HISTO2D_V3": + def from_string(cls, file_content: str) -> "GROGU_HISTO2D_V3": lines = file_content.strip().splitlines() - + key = "" + if find := re.search(r"BEGIN YODA_HISTO2D_V3 (\S+)", lines[0]): + key = find.group(1) # Extract metadata (path, title) path = "" title = "" @@ -207,7 +212,11 @@ def from_string(cls, file_content: str, key: str = "") -> "GROGU_HISTO2D_V3": data_section_started = False for line in lines: - if line.startswith("#"): + if line.startswith("BEGIN YODA_HISTO2D_V3"): + continue + if line.startswith("END YODA_HISTO2D_V3"): + break + if line.startswith("#") or line.isspace(): continue if line.startswith("---"): data_section_started = True @@ -216,17 +225,15 @@ def from_string(cls, file_content: str, key: str = "") -> "GROGU_HISTO2D_V3": continue if line.startswith("Edges"): - content = re.findall(r"\[(.*?)\]", line) - numbers_as_strings = re.findall( - r"[-+]?\d*\.\d+e[+-]?\d+|\d+", content[0] - ) - edges += [[float(i) for i in numbers_as_strings]] + content = re.findall(r"\[(.*?)\]", line)[0] + values = re.split(r"\s+", content.replace(",", "")) + edges += [[float(i) for i in values]] continue - bins.append(GROGU_HISTO2D_V3.Bin.from_string(line)) + bins.append(cls.Bin.from_string(line)) # Create and return the YODA_HISTO1D_V2 object - return GROGU_HISTO2D_V3( + return cls( d_key=key, d_path=path, d_title=title, diff --git a/src/babyyoda/grogu/read.py b/src/babyyoda/grogu/read.py index 16aaf3e..87935f9 100644 --- a/src/babyyoda/grogu/read.py +++ b/src/babyyoda/grogu/read.py @@ -10,23 +10,25 @@ def read(file_path: str): with open(file_path) as f: content = f.read() - pattern = re.compile(r"BEGIN (YODA_[A-Z0-9_]+) ([^\n]+)\n(.*?)\nEND \1", re.DOTALL) + pattern = re.compile( + r"(BEGIN (YODA_[A-Z0-9_]+) ([^\n]+)\n(.*?)\nEND \2)", re.DOTALL + ) matches = pattern.findall(content) histograms = {} - for hist_type, name, body in matches: + for full_match, hist_type, name, body in matches: if hist_type == "YODA_HISTO1D_V2": - hist = GROGU_HISTO1D_V2.from_string(body, name) + hist = GROGU_HISTO1D_V2.from_string(full_match) histograms[name] = hist elif hist_type == "YODA_HISTO1D_V3": - hist = GROGU_HISTO1D_V3.from_string(body, name) + hist = GROGU_HISTO1D_V3.from_string(full_match) histograms[name] = hist elif hist_type == "YODA_HISTO2D_V2": - hist = GROGU_HISTO2D_V2.from_string(body, name) + hist = GROGU_HISTO2D_V2.from_string(full_match) histograms[name] = hist elif hist_type == "YODA_HISTO2D_V3": - hist = GROGU_HISTO2D_V3.from_string(body, name) + hist = GROGU_HISTO2D_V3.from_string(full_match) histograms[name] = hist else: # Add other parsing logic for different types if necessary diff --git a/src/babyyoda/test.py b/src/babyyoda/test.py index 14d3ec2..a2fe5d4 100644 --- a/src/babyyoda/test.py +++ b/src/babyyoda/test.py @@ -59,7 +59,7 @@ def assert_value1d(gb, yb): assert gb.numEntries() == yb.numEntries() -def assert_equal_histo1d(gh1, yh1): +def assert_histo1d(gh1, yh1): assert_ao(gh1, yh1) assert len(gh1.bins()) == len(yh1.bins()), f"{len(gh1.bins())} != {len(yh1.bins())}" diff --git a/tests/babyyoda/test_histo1d.py b/tests/babyyoda/test_histo1d.py index 8d3e870..0a1a69c 100644 --- a/tests/babyyoda/test_histo1d.py +++ b/tests/babyyoda/test_histo1d.py @@ -1,6 +1,6 @@ import pytest from babyyoda.histo1D import Histo1D -from babyyoda.test import assert_equal_histo1d +from babyyoda.test import assert_histo1d import babyyoda.grogu as grogu @@ -44,7 +44,7 @@ def test_histos_equal(factory1, factory2): h1 = create_histo(factory1) h2 = create_histo(factory2) - assert_equal_histo1d(h1, h2) + assert_histo1d(h1, h2) @pytest.mark.parametrize( @@ -65,11 +65,11 @@ def test_histos_rebinby(factory1, factory2): # check that modifications happen with pytest.raises(AssertionError): - assert_equal_histo1d(o1, h1) + assert_histo1d(o1, h1) with pytest.raises(AssertionError): - assert_equal_histo1d(o2, h2) + assert_histo1d(o2, h2) - assert_equal_histo1d(h1, h2) + assert_histo1d(h1, h2) h1 = o1.clone() h2 = o2.clone() @@ -77,7 +77,7 @@ def test_histos_rebinby(factory1, factory2): h1.rebinBy(3, begin=2) h2.rebinBy(3, begin=2) - assert_equal_histo1d(h1, h2) + assert_histo1d(h1, h2) h1 = o1.clone() h2 = o2.clone() @@ -85,7 +85,7 @@ def test_histos_rebinby(factory1, factory2): h1.rebinBy(3, begin=2, end=7) h2.rebinBy(3, begin=2, end=7) - assert_equal_histo1d(h1, h2) + assert_histo1d(h1, h2) @pytest.mark.parametrize( @@ -106,8 +106,8 @@ def test_histos_rebinto(factory1, factory2): # check that modifications happen with pytest.raises(AssertionError): - assert_equal_histo1d(o1, h1) + assert_histo1d(o1, h1) with pytest.raises(AssertionError): - assert_equal_histo1d(o2, h2) + assert_histo1d(o2, h2) - assert_equal_histo1d(h1, h2) + assert_histo1d(h1, h2) diff --git a/tests/babyyoda/uhi/test_by_histo1d_slicing.py b/tests/babyyoda/uhi/test_by_histo1d_slicing.py index c972d42..e7b11c4 100644 --- a/tests/babyyoda/uhi/test_by_histo1d_slicing.py +++ b/tests/babyyoda/uhi/test_by_histo1d_slicing.py @@ -1,6 +1,6 @@ import pytest from babyyoda.histo1D import Histo1D -from babyyoda.test import assert_equal_histo1d +from babyyoda.test import assert_histo1d import babyyoda import babyyoda.grogu as grogu @@ -45,9 +45,9 @@ def create_histo(backend): def test_slicing_everything(factory1): yuhi1d = create_histo(factory1) assert yuhi1d.clone() != yuhi1d - assert_equal_histo1d(yuhi1d.clone(), yuhi1d) + assert_histo1d(yuhi1d.clone(), yuhi1d) assert yuhi1d[:] != yuhi1d - assert_equal_histo1d(yuhi1d[:], yuhi1d) + assert_histo1d(yuhi1d[:], yuhi1d) assert yuhi1d.clone()[:] != yuhi1d @@ -66,7 +66,7 @@ def test_slicing_subset(factory1): yuhi1d = create_histo(factory1) assert yuhi1d.clone()[1:3] != yuhi1d assert yuhi1d[1:3] != yuhi1d[1:3] - assert_equal_histo1d(yuhi1d[1:3], yuhi1d[1:3]) + assert_histo1d(yuhi1d[1:3], yuhi1d[1:3]) assert yuhi1d[1:3][0].sumW() == yuhi1d[1].sumW() @@ -118,18 +118,18 @@ def test_slicing_lower_bound(factory1): def test_slicing_mixed_bound(factory1): yuhi1d = create_histo(factory1) assert yuhi1d[1:9] != yuhi1d[1:-1] - assert_equal_histo1d(yuhi1d[1:9], yuhi1d[1:-1]) + assert_histo1d(yuhi1d[1:9], yuhi1d[1:-1]) assert yuhi1d[1:] != yuhi1d[1:10] - assert_equal_histo1d(yuhi1d[1:], yuhi1d[1:10]) + assert_histo1d(yuhi1d[1:], yuhi1d[1:10]) assert yuhi1d[1:][2:-1] != yuhi1d[1:10][2:8] - assert_equal_histo1d(yuhi1d[1:][2:-1], yuhi1d[1:10][2:8]) + assert_histo1d(yuhi1d[1:][2:-1], yuhi1d[1:10][2:8]) assert yuhi1d[:3][2:] != yuhi1d[:3][2:] - assert_equal_histo1d(yuhi1d[:3][2:], yuhi1d[:3][2:]) + assert_histo1d(yuhi1d[:3][2:], yuhi1d[:3][2:]) assert yuhi1d[:3][overflow].sumW() == yuhi1d[2:3][overflow].sumW() assert yuhi1d[:3][2:][overflow].sumW() == yuhi1d[2:3][overflow].sumW() assert yuhi1d[2:][:3] != yuhi1d[2:5] - assert_equal_histo1d(yuhi1d[2:][:3], yuhi1d[2:5]) + assert_histo1d(yuhi1d[2:][:3], yuhi1d[2:5]) @pytest.mark.parametrize( diff --git a/tests/grogu/test_gg_string.py b/tests/grogu/test_gg_string.py index 96e50cd..6d09e7f 100644 --- a/tests/grogu/test_gg_string.py +++ b/tests/grogu/test_gg_string.py @@ -1 +1,130 @@ # TODO test that from_string and to_string are inverses for bins and histograms + +import pytest +import babyyoda +from babyyoda.grogu.histo1d_v2 import GROGU_HISTO1D_V2 +from babyyoda.grogu.histo1d_v3 import GROGU_HISTO1D_V3 +from babyyoda.grogu.histo2d_v2 import GROGU_HISTO2D_V2 +from babyyoda.grogu.histo2d_v3 import GROGU_HISTO2D_V3 +from babyyoda.test import assert_bin1d, assert_histo1d, assert_histo2d + + +@pytest.mark.parametrize( + "args, kwargs, label", + [ + ([0, 1, 5, 6, 7, 8, 10], {}, None), + ([0.0, 1.0, 5.0, 6.0, 7.0, 8.0, 10.0], {}, None), + ( + [], + { + "d_xmin": 0, + "d_xmax": 1, + "d_sumw": 5, + "d_sumw2": 6, + "d_sumwx": 7, + "d_sumwx2": 8, + "d_numentries": 10, + }, + None, + ), + ( + [], + { + "d_xmin": 0.0, + "d_xmax": 1.0, + "d_sumw": 5.0, + "d_sumw2": 6.0, + "d_sumwx": 7.0, + "d_sumwx2": 8.0, + "d_numentries": 10, + }, + None, + ), + ( + [], + { + "d_xmin": None, + "d_xmax": None, + "d_sumw": 5.0, + "d_sumw2": 6.0, + "d_sumwx": 7.0, + "d_sumwx2": 8.0, + "d_numentries": 10, + }, + "Overflow", + ), + ( + [], + { + "d_xmin": None, + "d_xmax": None, + "d_sumw": 5.0, + "d_sumw2": 6.0, + "d_sumwx": 7.0, + "d_sumwx2": 8.0, + "d_numentries": 10, + }, + "Underflow", + ), + ], +) +def test_gg_histo1d_v2_bin_string(args, kwargs, label): + b1 = GROGU_HISTO1D_V2.Bin(*args, **kwargs) + s = b1.to_string(label) + b2 = GROGU_HISTO1D_V2.Bin.from_string(s) + assert_bin1d(b1, b2) + assert b1 == b2 + + +def test_gg_histo1d_v2_string(): + h1 = babyyoda.grogu.Histo1D_v2(10, 0, 10, title="test") + w = 0 + for i in range(-10, 12): + w += 1 + h1.fill(i, w) + s = h1.to_string() + print(s) + h2 = GROGU_HISTO1D_V2.from_string(s) + assert_histo1d(h1, h2) + assert h1 == h2 + + +def test_gg_histo1d_v3_string(): + h1 = babyyoda.grogu.Histo1D_v3(10, 0, 10, title="test") + w = 0 + for i in range(-10, 12): + w += 1 + h1.fill(i, w) + s = h1.to_string() + print(s) + h2 = GROGU_HISTO1D_V3.from_string(s) + assert_histo1d(h1, h2) + assert h1 == h2 + + +def test_gg_histo2d_v2_string(): + h1 = babyyoda.grogu.Histo2D_v2(10, 0, 10, 10, 0, 10, title="test") + w = 0 + for i in range(-10, 12): + for j in range(-10, 12): + w += 1 + h1.fill(i, j, w) + s = h1.to_string() + print(s) + h2 = GROGU_HISTO2D_V2.from_string(s) + assert_histo2d(h1, h2, includeFlow=False) + assert h1 == h2 + + +def test_gg_histo2d_v3_string(): + h1 = babyyoda.grogu.Histo2D_v3(10, 0, 10, 10, 0, 10, title="test") + w = 0 + for i in range(-10, 12): + for j in range(-10, 12): + w += 1 + h1.fill(i, j, w) + s = h1.to_string() + print(s) + h2 = GROGU_HISTO2D_V3.from_string(s) + assert_histo2d(h1, h2, includeFlow=True) + assert h1 == h2 diff --git a/tests/grogu/uhi/test_gg_histo1d_slicing.py b/tests/grogu/uhi/test_gg_histo1d_slicing.py index c042446..0936fbc 100644 --- a/tests/grogu/uhi/test_gg_histo1d_slicing.py +++ b/tests/grogu/uhi/test_gg_histo1d_slicing.py @@ -1,6 +1,6 @@ from babyyoda.histo1D import Histo1D import babyyoda.grogu as yoda -from babyyoda.test import assert_equal_histo1d +from babyyoda.test import assert_histo1d from babyyoda.util import loc, overflow, underflow @@ -17,9 +17,9 @@ def get_histo1d(): def test_slicing_everything(): yuhi1d = get_histo1d() assert yuhi1d.clone() != yuhi1d - assert_equal_histo1d(yuhi1d.clone(), yuhi1d) + assert_histo1d(yuhi1d.clone(), yuhi1d) assert yuhi1d[:] != yuhi1d - assert_equal_histo1d(yuhi1d[:], yuhi1d) + assert_histo1d(yuhi1d[:], yuhi1d) assert yuhi1d.clone()[:] != yuhi1d @@ -27,7 +27,7 @@ def test_slicing_subset(): yuhi1d = get_histo1d() assert yuhi1d.clone()[1:3] != yuhi1d assert yuhi1d[1:3] != yuhi1d[1:3] - assert_equal_histo1d(yuhi1d[1:3], yuhi1d[1:3]) + assert_histo1d(yuhi1d[1:3], yuhi1d[1:3]) assert yuhi1d[1:3][0].sumW() == yuhi1d[1].sumW() @@ -46,18 +46,18 @@ def test_slicing_lower_bound(): def test_slicing_mixed_bound(): yuhi1d = get_histo1d() assert yuhi1d[1:9] != yuhi1d[1:-1] - assert_equal_histo1d(yuhi1d[1:9], yuhi1d[1:-1]) + assert_histo1d(yuhi1d[1:9], yuhi1d[1:-1]) assert yuhi1d[1:] != yuhi1d[1:10] - assert_equal_histo1d(yuhi1d[1:], yuhi1d[1:10]) + assert_histo1d(yuhi1d[1:], yuhi1d[1:10]) assert yuhi1d[1:][2:-1] != yuhi1d[1:10][2:8] - assert_equal_histo1d(yuhi1d[1:][2:-1], yuhi1d[1:10][2:8]) + assert_histo1d(yuhi1d[1:][2:-1], yuhi1d[1:10][2:8]) assert yuhi1d[:3][2:] != yuhi1d[:3][2:] - assert_equal_histo1d(yuhi1d[:3][2:], yuhi1d[:3][2:]) + assert_histo1d(yuhi1d[:3][2:], yuhi1d[:3][2:]) assert yuhi1d[:3][overflow].sumW() == yuhi1d[2:3][overflow].sumW() assert yuhi1d[:3][2:][overflow].sumW() == yuhi1d[2:3][overflow].sumW() assert yuhi1d[2:][:3] != yuhi1d[2:5] - assert_equal_histo1d(yuhi1d[2:][:3], yuhi1d[2:5]) + assert_histo1d(yuhi1d[2:][:3], yuhi1d[2:5]) def test_slicing_overflow(): diff --git a/tests/yoda/test_yoda_vs_grogu.py b/tests/yoda/test_yoda_vs_grogu.py index 3dae613..e172ec1 100644 --- a/tests/yoda/test_yoda_vs_grogu.py +++ b/tests/yoda/test_yoda_vs_grogu.py @@ -4,7 +4,7 @@ from babyyoda.histo2D import Histo2D from babyyoda.grogu.histo1d_v2 import GROGU_HISTO1D_V2 from babyyoda.grogu.histo2d_v2 import GROGU_HISTO2D_V2 -from babyyoda.test import assert_ao, assert_equal_histo1d, assert_histo2d +from babyyoda.test import assert_ao, assert_histo1d, assert_histo2d pytest.importorskip("yoda") @@ -128,7 +128,7 @@ def test_create_histo1d(): h.fill(10) g.fill(10) - assert_equal_histo1d(Histo1D(g), Histo1D(h)) + assert_histo1d(Histo1D(g), Histo1D(h)) def test_create_histo2d():