nebius/SWE-bench-extra huggingface dataset:
Repository: cta-observatory/pyirf

Issue:
angular resolution function does not respect units of theta in input
Due to how astropy tables work, the input is assumed to be degrees.

Comments:

Patch:
diff --git a/pyirf/benchmarks/angular_resolution.py b/pyirf/benchmarks/angular_resolution.py
index a5c120d..c1bcb1b 100644
--- a/pyirf/benchmarks/angular_resolution.py
+++ b/pyirf/benchmarks/angular_resolution.py
@@ -51,7 +51,7 @@ def angular_resolution(
     result[f"{energy_type}_energy_high"] = energy_bins[1:]
     result[f"{energy_type}_energy_center"] = 0.5 * (energy_bins[:-1] + energy_bins[1:])
 
-    result["angular_resolution"] = np.nan * u.deg
+    result["angular_resolution"] = u.Quantity(np.nan, table["theta"].unit)
 
     if not len(events):
         # if we get an empty input (no selected events available)


Test patch:
diff --git a/pyirf/benchmarks/tests/test_angular_resolution.py b/pyirf/benchmarks/tests/test_angular_resolution.py
index 5ae0044..c3aa192 100644
--- a/pyirf/benchmarks/tests/test_angular_resolution.py
+++ b/pyirf/benchmarks/tests/test_angular_resolution.py
@@ -1,6 +1,7 @@
 from astropy.table import QTable
 import astropy.units as u
 import numpy as np
+import pytest
 
 
 def test_empty_angular_resolution():
@@ -18,7 +19,8 @@ def test_empty_angular_resolution():
 
     assert np.all(np.isnan(table["angular_resolution"]))
 
-def test_angular_resolution():
+@pytest.mark.parametrize("unit", (u.deg, u.rad))
+def test_angular_resolution(unit):
     from pyirf.benchmarks import angular_resolution
 
     np.random.seed(1337)
@@ -37,6 +39,8 @@ def test_angular_resolution():
         'theta': np.abs(np.random.normal(0, true_resolution)) * u.deg
     })
 
+    events['theta'] = events['theta'].to(unit)
+
     ang_res = angular_resolution(
         events,
         [1, 10, 100] * u.TeV,
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.

Comments:

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])
Repository: cthoyt/class-resolver

Issue:
Combine subclass and entrypoint instantiation
While the entrypoint loader in PyKEEN seems to be very clever, it's still sort of a problem for collab users. It might be better to provide a mixed version where there are some base classes that are in PyKEEN, plus the possibility to add extra stuff

Comments:

Patch:
diff --git a/src/class_resolver/base.py b/src/class_resolver/base.py
index 138ab7e..0b5aad7 100644
--- a/src/class_resolver/base.py
+++ b/src/class_resolver/base.py
@@ -234,6 +234,11 @@ class BaseResolver(ABC, Generic[X, Y]):
             **kwargs,
         )
 
+    def register_entrypoint(self, group: str) -> None:
+        """Register additional entries from an entrypoint."""
+        for element in self._from_entrypoint(group).difference(self.lookup_dict.values()):
+            self.register(element)
+
     @staticmethod
     def _from_entrypoint(group: str) -> Set[X]:
         elements = set()


Test patch:
diff --git a/tests/test_function_resolver.py b/tests/test_function_resolver.py
index e32948a..c2b498b 100644
--- a/tests/test_function_resolver.py
+++ b/tests/test_function_resolver.py
@@ -2,6 +2,7 @@
 
 """Tests for the function resolver."""
 
+import operator
 import unittest
 
 from class_resolver import FunctionResolver
@@ -102,3 +103,12 @@ class TestFunctionResolver(unittest.TestCase):
         self.assertEqual({"add", "sub", "mul"}, set(resolver.lookup_dict))
         self.assertEqual(set(), set(resolver.synonyms))
         self.assertNotIn("expected_failure", resolver.lookup_dict)
+
+    def test_late_entrypoints(self):
+        """Test loading late entrypoints."""
+        resolver = FunctionResolver([operator.add, operator.sub])
+        self.assertEqual({"add", "sub"}, set(resolver.lookup_dict))
+        resolver.register_entrypoint("class_resolver_demo")
+        self.assertEqual({"add", "sub", "mul"}, set(resolver.lookup_dict))
+        self.assertEqual(set(), set(resolver.synonyms))
+        self.assertNotIn("expected_failure", resolver.lookup_dict)
Repository: cthoyt/pystow

Issue:
Get configuration from file corresponding to leading part
If I want to use `zenodo:sandbox` as a key, it should figure to look in `zenodo.ini` and other `zenodo.*` files if they exist

Comments:

Patch:
diff --git a/src/pystow/config_api.py b/src/pystow/config_api.py
index 270e4f5..dca56d4 100644
--- a/src/pystow/config_api.py
+++ b/src/pystow/config_api.py
@@ -77,6 +77,12 @@ def get_home(ensure_exists: bool = True) -> Path:
 def _get_cfp(module: str) -> ConfigParser:
     cfp = ConfigParser()
     directory = get_home()
+
+    # If a multi-part module was given like "zenodo:sandbox",
+    # then only look for the first part "zenodo" as the file name
+    if ":" in module:
+        module = module.split(":", 1)[0]
+
     filenames = [
         os.path.join(directory, "config.cfg"),
         os.path.join(directory, "config.ini"),
@@ -157,7 +163,12 @@ def write_config(module: str, key: str, value: str) -> None:
     """
     _get_cfp.cache_clear()
     cfp = ConfigParser()
-    path = get_home() / f"{module}.ini"
+
+    # If there's a multi-part module such as "zenodo:sandbox",
+    # then write to zenodo.ini with section [zenodo:sandbox]
+    fname = module.split(":", 1)[0] if ":" in module else module
+
+    path = get_home().joinpath(fname).with_suffix(".ini")
     cfp.read(path)
 
     # If the file did not exist, then this section will be empty


Test patch:
diff --git a/tests/test_config.py b/tests/test_config.py
index a641ad4..e16da5d 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -2,10 +2,12 @@
 
 """Test configuration loading."""
 
+import tempfile
 import unittest
+from pathlib import Path
 
 import pystow
-from pystow.config_api import _get_cfp
+from pystow.config_api import CONFIG_HOME_ENVVAR, _get_cfp
 from pystow.utils import mock_envvar
 
 
@@ -91,3 +93,18 @@ class TestConfig(unittest.TestCase):
         self.assertEqual(
             True, pystow.get_config(self.test_section, self.test_option, passthrough=1, dtype=bool)
         )
+
+    def test_subsection(self):
+        """Test subsections."""
+        with tempfile.TemporaryDirectory() as directory, mock_envvar(CONFIG_HOME_ENVVAR, directory):
+            directory = Path(directory)
+            path = directory.joinpath("test.ini")
+            self.assertFalse(path.is_file(), msg="file should not already exist")
+
+            self.assertIsNone(pystow.get_config("test:subtest", "key"))
+            self.assertFalse(path.is_file(), msg="getting config should not create a file")
+
+            pystow.write_config("test:subtest", "key", "value")
+            self.assertTrue(path.is_file(), msg=f"{list(directory.iterdir())}")
+
+            self.assertEqual("value", pystow.get_config("test:subtest", "key"))