Repository: cta-observatory/pyirf

Issue:
Empty column in `pyirf.benchmarks.angular_resolution()`
The function `pyirf.benchmarks.angular_resolution()` returns a QTable containing a column `n_events`, which values are always 0 as the column is not filled.

Discussion:

Patch:
diff --git a/docs/changes/231.bugfix.rst b/docs/changes/231.bugfix.rst
new file mode 100644
index 0000000..304af8b
--- /dev/null
+++ b/docs/changes/231.bugfix.rst
@@ -0,0 +1,1 @@
+Correctly fill n_events in ``angular_resolution``, was always 0 before.
diff --git a/pyirf/benchmarks/angular_resolution.py b/pyirf/benchmarks/angular_resolution.py
index 9400b03..91e0cd0 100644
--- a/pyirf/benchmarks/angular_resolution.py
+++ b/pyirf/benchmarks/angular_resolution.py
@@ -58,4 +58,5 @@ def angular_resolution(
     by_bin = table[valid].group_by(bin_index[valid])
     for bin_idx, group in zip(by_bin.groups.keys, by_bin.groups):
         result[key][bin_idx] = np.nanquantile(group["theta"], ONE_SIGMA_QUANTILE)
+        result["n_events"][bin_idx] = len(group)
     return result


Test patch:
diff --git a/pyirf/benchmarks/tests/test_angular_resolution.py b/pyirf/benchmarks/tests/test_angular_resolution.py
index 6295447..1a1c179 100644
--- a/pyirf/benchmarks/tests/test_angular_resolution.py
+++ b/pyirf/benchmarks/tests/test_angular_resolution.py
@@ -45,11 +45,15 @@ def test_angular_resolution(unit):
     events["true_energy"].value[500] = np.nan
     events["true_energy"].value[1500] = np.nan
 
-    ang_res = angular_resolution(
+    table = angular_resolution(
         events,
         [1, 10, 100] * u.TeV,
-    )['angular_resolution']
+    )
 
+    ang_res = table['angular_resolution']
     assert len(ang_res) == 2
     assert u.isclose(ang_res[0], TRUE_RES_1 * u.deg, rtol=0.05)
     assert u.isclose(ang_res[1], TRUE_RES_2 * u.deg, rtol=0.05)
+
+    # one value in each bin is nan, which is ignored
+    np.testing.assert_array_equal(table["n_events"], [998, 998])