From 4b0b379d2cdac144c72e0a084303d073e5128e6c Mon Sep 17 00:00:00 2001 From: Rachit931 Date: Mon, 22 Dec 2025 20:41:45 +0530 Subject: [PATCH 1/4] Improving the fill error message to report the missing axis names --- src/hist/basehist.py | 12 ++++++++++-- tests/test_general.py | 11 +++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/hist/basehist.py b/src/hist/basehist.py index c28b8823..a3c9af78 100644 --- a/src/hist/basehist.py +++ b/src/hist/basehist.py @@ -292,8 +292,16 @@ def fill( } if set(data_dict) != set(range(len(args), self.ndim)): - raise TypeError( - "All axes must be accounted for in fill, you may have used a disallowed name in the axes" + + expected = set(range(len(args), self.ndim)) + provided = set(data_dict) + + missing = expected - provided + missing_values = [self.axes[i].name for i in missing] + + raise TypeError ( + f"Missing values for single/multiple axis : {missing_values}." + f"Expected axes : {[ax.name for ax in self.axes]}" ) data = (data_dict[i] for i in range(len(args), self.ndim)) diff --git a/tests/test_general.py b/tests/test_general.py index 1d13ad92..da995402 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -1021,3 +1021,14 @@ def test_T_3D(): assert h_3D.T.axes[0] == h_3D.axes[2] assert h_3D.T.axes[1] == h_3D.axes[1] assert h_3D.T.axes[2] == h_3D.axes[0] + + +def test_fill_missing_axis_reports_axis_name() : + h = Hist ( + axis.Regular(5,0,1, name = "x"), + axis.Regular(5,0,1, name = "y"), + ) + + with pytest.raises(TypeError) as exc : + h.fill(x = [0.1, 0.2]) + \ No newline at end of file From cb2edaaf5afc4bac3fb607f0146da08702efd856 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 22 Dec 2025 15:47:42 +0000 Subject: [PATCH 2/4] style: pre-commit fixes --- src/hist/basehist.py | 5 ++--- tests/test_general.py | 13 ++++++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/hist/basehist.py b/src/hist/basehist.py index a3c9af78..e8e791ec 100644 --- a/src/hist/basehist.py +++ b/src/hist/basehist.py @@ -292,14 +292,13 @@ def fill( } if set(data_dict) != set(range(len(args), self.ndim)): - expected = set(range(len(args), self.ndim)) provided = set(data_dict) - missing = expected - provided + missing = expected - provided missing_values = [self.axes[i].name for i in missing] - raise TypeError ( + raise TypeError( f"Missing values for single/multiple axis : {missing_values}." f"Expected axes : {[ax.name for ax in self.axes]}" ) diff --git a/tests/test_general.py b/tests/test_general.py index da995402..34e132da 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -1023,12 +1023,11 @@ def test_T_3D(): assert h_3D.T.axes[2] == h_3D.axes[0] -def test_fill_missing_axis_reports_axis_name() : - h = Hist ( - axis.Regular(5,0,1, name = "x"), - axis.Regular(5,0,1, name = "y"), +def test_fill_missing_axis_reports_axis_name(): + h = Hist( + axis.Regular(5, 0, 1, name="x"), + axis.Regular(5, 0, 1, name="y"), ) - with pytest.raises(TypeError) as exc : - h.fill(x = [0.1, 0.2]) - \ No newline at end of file + with pytest.raises(TypeError) as exc: + h.fill(x=[0.1, 0.2]) From 6f84b089add9c0d01572ad4ea500f738f7113743 Mon Sep 17 00:00:00 2001 From: Rachit931 Date: Mon, 22 Dec 2025 21:34:26 +0530 Subject: [PATCH 3/4] Removal of unsed python exc variable --- tests/test_general.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_general.py b/tests/test_general.py index 34e132da..929499de 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -1029,5 +1029,6 @@ def test_fill_missing_axis_reports_axis_name(): axis.Regular(5, 0, 1, name="y"), ) - with pytest.raises(TypeError) as exc: - h.fill(x=[0.1, 0.2]) + with pytest.raises(TypeError) : + h.fill(x = [0.1, 0.2]) + From 48c531dbb5d9558f051f0303867b11cba3dbef39 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 22 Dec 2025 16:11:33 +0000 Subject: [PATCH 4/4] style: pre-commit fixes --- tests/test_general.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/test_general.py b/tests/test_general.py index 929499de..c4c5cded 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -1029,6 +1029,5 @@ def test_fill_missing_axis_reports_axis_name(): axis.Regular(5, 0, 1, name="y"), ) - with pytest.raises(TypeError) : - h.fill(x = [0.1, 0.2]) - + with pytest.raises(TypeError): + h.fill(x=[0.1, 0.2])