nebius/SWE-bench-extra huggingface dataset:
Repository: DCC-Lab/RayTracing

Issue:
ImagingPath: chiefRay not working with no aperture stop
When we create an `ImagingPath` without any aperture stop, `chiefRay` raises a `TypeError`, because there is no aperture stop. For example:

```python
path = ImagingPath(System2f(10)) # A 2f system with f = 10 and infinite diameter
path.chiefRay() # Fails with TypeError, even with a specified y
```
I think we should return `None`, because no aperture stop means no specific chief ray.

Comments:

Patch:
diff --git a/raytracing/imagingpath.py b/raytracing/imagingpath.py
index 82765ea..6a7e46b 100644
--- a/raytracing/imagingpath.py
+++ b/raytracing/imagingpath.py
@@ -151,8 +151,12 @@ class ImagingPath(MatrixGroup):
         If the element B in the transfer matrix for the imaging path
         is zero, there is no value for the height and angle that makes
         a proper chief ray. So the function will return None.
+        If there is no aperture stop, there is no chief ray either. None is also returned.
         """
         (stopPosition, stopDiameter) = self.apertureStop()
+        if stopPosition is None:
+            return None
+
         transferMatrixToApertureStop = self.transferMatrix(upTo=stopPosition)
         A = transferMatrixToApertureStop.A
         B = transferMatrixToApertureStop.B


Test patch:
diff --git a/raytracing/tests/testsImagingPath.py b/raytracing/tests/testsImagingPath.py
index 4e9ed76..b543b8b 100644
--- a/raytracing/tests/testsImagingPath.py
+++ b/raytracing/tests/testsImagingPath.py
@@ -56,6 +56,10 @@ class TestImagingPath(unittest.TestCase):
         path = ImagingPath(elements)
         self.assertIsNotNone(path.entrancePupil())
 
+    def testChiefRayNoApertureStop(self):
+        path = ImagingPath(System2f(10))
+        chiefRay = path.chiefRay()
+        self.assertIsNone(chiefRay)
 
 if __name__ == '__main__':
     unittest.main()
Repository: DCC-Lab/RayTracing

Issue:
ImagingPath: imageSize fails when D is 0
When `D == 0`, there is no forward conjugate (nor backward), so we return `conjugateMatrix` as `None`. Because of that, `imageSize` raises an `AttributeError`. We should check if `conjugateMatrix` is `None`, but what should we return? Since there is no image, return `None`?

Comments:

Patch:
diff --git a/raytracing/imagingpath.py b/raytracing/imagingpath.py
index 9960d83..6c89bff 100644
--- a/raytracing/imagingpath.py
+++ b/raytracing/imagingpath.py
@@ -585,6 +585,9 @@ class ImagingPath(MatrixGroup):
         """
         fieldOfView = self.fieldOfView()
         (distance, conjugateMatrix) = self.forwardConjugate()
+        if conjugateMatrix is None:
+            return float("+inf")
+
         magnification = conjugateMatrix.A
         return abs(fieldOfView * magnification)
 


Test patch:
diff --git a/raytracing/tests/testsImagingPath.py b/raytracing/tests/testsImagingPath.py
index b543b8b..2e24ab7 100644
--- a/raytracing/tests/testsImagingPath.py
+++ b/raytracing/tests/testsImagingPath.py
@@ -61,5 +61,10 @@ class TestImagingPath(unittest.TestCase):
         chiefRay = path.chiefRay()
         self.assertIsNone(chiefRay)
 
+    def testImageSizeDIs0(self):
+        path = ImagingPath(System2f(f=10, diameter=10))
+        path.append(Aperture(20))
+        self.assertEqual(path.imageSize(), inf)
+
 if __name__ == '__main__':
     unittest.main()
Repository: DCC-Lab/RayTracing

Issue:
ImagingPath: chiefRay doesn't return None when B is very close but not 0
When `B == 0` in an `ImagingPath` instance, there is no chief ray. But because we use a computer, some calculations can lead to something close to 0 but not quite 0. For example:
```python
path = ImagingPath(System4f(pi * 2, pi * 1.25)) # This is an imaging system with B = 0
path.append(System4f(pi, pi / 1.2)) # This is another imaging system with B = 0
path.append(Aperture(10))
self.assertIsNone(path.chiefRay()) # This fails because B is close to but not 0 (approx. -7e-16)
```

Comments:

Patch:
diff --git a/raytracing/imagingpath.py b/raytracing/imagingpath.py
index aa348eb..5c3b21d 100644
--- a/raytracing/imagingpath.py
+++ b/raytracing/imagingpath.py
@@ -161,7 +161,7 @@ class ImagingPath(MatrixGroup):
         A = transferMatrixToApertureStop.A
         B = transferMatrixToApertureStop.B
 
-        if B == 0:
+        if transferMatrixToApertureStop.isImaging:
             return None
 
         if y is None:


Test patch:
diff --git a/raytracing/tests/testsImagingPath.py b/raytracing/tests/testsImagingPath.py
index a6b39da..4239a06 100644
--- a/raytracing/tests/testsImagingPath.py
+++ b/raytracing/tests/testsImagingPath.py
@@ -61,6 +61,12 @@ class TestImagingPath(unittest.TestCase):
         chiefRay = path.chiefRay()
         self.assertIsNone(chiefRay)
 
+    def testChiefRayBIs0(self):
+        path = ImagingPath(System4f(pi*2, pi*1.25))
+        path.append(System4f(pi, pi/1.2))
+        path.append(Aperture(10))
+        self.assertIsNone(path.chiefRay())
+
     def testChiefRayInfiniteFieldOfViewNoY(self):
         path = ImagingPath()
         path.append(System2f(10, path.maxHeight + 1))
@@ -81,5 +87,6 @@ class TestImagingPath(unittest.TestCase):
         path.append(Aperture(20))
         self.assertEqual(path.imageSize(), inf)
 
+
 if __name__ == '__main__':
     unittest.main()
Repository: DCC-Lab/RayTracing

Issue:
ImagingPath: chiefRay returns y=inf and theta=-inf with really big (but not infinite) aperture and no specific y given
When we create an `ImagingPath` with a really big aperture stop (but not infinite), the chief ray obtained has y = -theta = inf. This doesn't really make sense.

This happens because the aperture is bigger than the max height and at one point (in `fieldOfView`), if `abs(y) < self.maxHeight`, we return `float("+inf")`. If the aperture is bigger than the max height accepted, then we should consider it like an infite aperture?

Example:
```python
path = ImagingPath(System2f(10, 100_000)) # 2f system with f = 10 and 100_000 units aperture
print(path.chiefRay())
```
The output is:
```python
 /       \ 
|    inf  |
|         |
|   -inf  |
 \       /

z = 0.000
```

Comments:

Patch:
diff --git a/raytracing/imagingpath.py b/raytracing/imagingpath.py
index eaea927..aa348eb 100644
--- a/raytracing/imagingpath.py
+++ b/raytracing/imagingpath.py
@@ -166,6 +166,8 @@ class ImagingPath(MatrixGroup):
 
         if y is None:
             y = self.fieldOfView()
+            if abs(y) == float("+inf"):
+                raise ValueError("Must provide y when the filed of view is infinite")
 
         return Ray(y=y, theta=-A * y / B)
 


Test patch:
diff --git a/raytracing/tests/testsImagingPath.py b/raytracing/tests/testsImagingPath.py
index 6590fe8..a6b39da 100644
--- a/raytracing/tests/testsImagingPath.py
+++ b/raytracing/tests/testsImagingPath.py
@@ -61,6 +61,12 @@ class TestImagingPath(unittest.TestCase):
         chiefRay = path.chiefRay()
         self.assertIsNone(chiefRay)
 
+    def testChiefRayInfiniteFieldOfViewNoY(self):
+        path = ImagingPath()
+        path.append(System2f(10, path.maxHeight + 1))
+        with self.assertRaises(ValueError):
+            path.chiefRay()
+
     def testMarginalRaysNoApertureStop(self):
         path = ImagingPath(System4f(10, 10))
         self.assertIsNone(path.marginalRays())
Repository: DCC-Lab/RayTracing

Issue:
ImagingPath: division by 0 in marginalRays
When we have an `ImagingPath` that has a transfer matrix to the aperture stop with `B == 0`, there is a division by 0 in the calculations of theta + and -. We should check when it's the case and return `None`.

Comments:

Patch:
diff --git a/raytracing/imagingpath.py b/raytracing/imagingpath.py
index 6c89bff..b9ee7de 100644
--- a/raytracing/imagingpath.py
+++ b/raytracing/imagingpath.py
@@ -260,6 +260,9 @@ class ImagingPath(MatrixGroup):
         A = transferMatrixToApertureStop.A
         B = transferMatrixToApertureStop.B
 
+        if transferMatrixToApertureStop.isImaging:
+            return None
+
         thetaUp  = (stopDiameter / 2.0 - A * y) / B
         thetaDown = (-stopDiameter / 2.0 - A * y) / B
 


Test patch:
diff --git a/raytracing/tests/testsImagingPath.py b/raytracing/tests/testsImagingPath.py
index 2e24ab7..be8f0e1 100644
--- a/raytracing/tests/testsImagingPath.py
+++ b/raytracing/tests/testsImagingPath.py
@@ -61,6 +61,11 @@ class TestImagingPath(unittest.TestCase):
         chiefRay = path.chiefRay()
         self.assertIsNone(chiefRay)
 
+    def testMarginalRaysIsImaging(self):
+        path = ImagingPath(System4f(10, 10))
+        path.append(Aperture(10))
+        self.assertIsNone(path.marginalRays())
+
     def testImageSizeDIs0(self):
         path = ImagingPath(System2f(f=10, diameter=10))
         path.append(Aperture(20))
Repository: DCC-Lab/RayTracing

Issue:
Matrix: hasPower returns True when it should be False
When we want to know if a `Matrix` has power, we check if `self.C != 0`. In some cases, computational errors occurs due to the fact that we are handling floats and `self.C` is really close to 0. Example:
```python
d1 = 1.0000000000000017 # Some computation errors tend to add digits at the end of the number
d2 = 1.0000000000000017 * 2.05
matrixGroup = System4f(d1, d2) # We use a 4f system because it is a real physical system
# Any matrix with C close but not 0 will do
print(matrixGroup.C) # We check what is the value of the C component of the ewuivalent matrix
```
The output is:
```python
1.1102230246251565e-16
```
Which is **VERY** small, but still not 0. Obviously, a 4f system has no power, but with computational errors, the code considers it has power.

Comments:

Patch:
diff --git a/raytracing/matrix.py b/raytracing/matrix.py
index 43f9790..c84cede 100644
--- a/raytracing/matrix.py
+++ b/raytracing/matrix.py
@@ -846,7 +846,8 @@ class Matrix(object):
 
     @property
     def hasPower(self):
-        """ If True, then there is a non-null focal length because C!=0
+        """ If True, then there is a non-null focal length because C!=0. We compare to an epsilon value, because
+        computational errors can occur and lead to C being very small, but not 0.
 
         Examples
         --------
@@ -861,7 +862,7 @@ class Matrix(object):
         >>> print('hasPower:' , M2.hasPower)
         hasPower: False
         """
-        return self.C != 0
+        return abs(self.C) > Matrix.__epsilon__
 
     def pointsOfInterest(self, z):
         """ Any points of interest for this matrix (focal points,


Test patch:
diff --git a/raytracing/tests/testsMatrix.py b/raytracing/tests/testsMatrix.py
index 9c75340..886a9b4 100644
--- a/raytracing/tests/testsMatrix.py
+++ b/raytracing/tests/testsMatrix.py
@@ -344,6 +344,15 @@ class TestMatrix(unittest.TestCase):
         m2 = Matrix(A=1, B=1, C=3, D=4)
         self.assertFalse(m2.isImaging)
 
+    def testHasNoPower(self):
+        f1 = 1.0000000000000017
+        f2 = 2.05 * f1
+
+        # This simulates a 4f system (since we test Matrix, we should only use basic matrices)
+        m = Matrix(1, f1, 0, 1) * Matrix(1, 0, -1 / f1, 1) * Matrix(1, f1, 0, 1) * Matrix(1, f2, 0, 1)
+        m = m * Matrix(1, 0, -1 / f2, 1) * Matrix(1, f1, 0, 1)
+        self.assertFalse(m.hasPower)
+
     def testEffectiveFocalLengthsHasPower(self):
         m = Matrix(1, 2, 3, 4)
         focalLengths = (-1 / 3, -1 / 3)
Repository: DCC-Lab/RayTracing

Issue:
Matrix accepts a negative aperture diameter
This doesn't make any sense. Even the doc specifies that it must be positive.

Comments:

Patch:
diff --git a/raytracing/matrix.py b/raytracing/matrix.py
index 2f8ff11..7f32c1b 100644
--- a/raytracing/matrix.py
+++ b/raytracing/matrix.py
@@ -122,6 +122,8 @@ class Matrix(object):
         # Length of this element
         self.L = float(physicalLength)
         # Aperture
+        if apertureDiameter <= 0:
+            raise ValueError("The aperture diameter must be strictly positive.")
         self.apertureDiameter = apertureDiameter
 
         # First and last interfaces. Used for BFL and FFL
@@ -163,7 +165,7 @@ class Matrix(object):
 
         if self.C == 0:
             return self.A * self.D
-        
+
         return self.A * self.D - self.B * self.C
 
     def __mul__(self, rightSide):


Test patch:
diff --git a/raytracing/tests/testsMatrix.py b/raytracing/tests/testsMatrix.py
index f36fe01..c160580 100644
--- a/raytracing/tests/testsMatrix.py
+++ b/raytracing/tests/testsMatrix.py
@@ -20,9 +20,17 @@ class TestMatrix(envtest.RaytracingTestCase):
         m = Matrix()
         self.assertIsNotNone(m)
 
+    def testNullApertureDiameter(self):
+        with self.assertRaises(ValueError):
+            Matrix(apertureDiameter=0)
+
+    def testNegativeApertureDiameter(self):
+        with self.assertRaises(ValueError):
+            Matrix(apertureDiameter=-0.1)
+
     def testMatrixExplicit(self):
         m = Matrix(A=1, B=0, C=0, D=1, physicalLength=1,
-                   frontVertex=0, backVertex=0, apertureDiameter=1.0)
+                   frontVertex=0, backVertex=0, apertureDiameter=0.5)
         self.assertIsNotNone(m)
         self.assertEqual(m.A, 1)
         self.assertEqual(m.B, 0)
@@ -31,7 +39,7 @@ class TestMatrix(envtest.RaytracingTestCase):
         self.assertEqual(m.L, 1)
         self.assertEqual(m.backVertex, 0)
         self.assertEqual(m.frontVertex, 0)
-        self.assertEqual(m.apertureDiameter, 1)
+        self.assertEqual(m.apertureDiameter, 0.5)
 
     def testMatrixProductMath(self):
         m1 = Matrix(A=4, B=3, C=1, D=1)
@@ -586,16 +594,16 @@ class TestMatrix(envtest.RaytracingTestCase):
         self.assertNotEqual(m, "Trust me, this is a Matrix. This is equal to Matrix()")
 
     def testEqualityMatricesNotEqualSameABCD(self):
-        m = Matrix(1,0,0,1)
-        m2 = Matrix(1,0,0,1, frontVertex=1)
+        m = Matrix(1, 0, 0, 1)
+        m2 = Matrix(1, 0, 0, 1, frontVertex=1)
         self.assertNotEqual(m, m2)
-        m2 = Matrix(1,0,0,1, backVertex=1)
+        m2 = Matrix(1, 0, 0, 1, backVertex=1)
         self.assertNotEqual(m, m2)
-        m2 = Matrix(1,0,0,1, frontIndex=10, backIndex=10)
+        m2 = Matrix(1, 0, 0, 1, frontIndex=10, backIndex=10)
         self.assertNotEqual(m, m2)
 
     def testEqualityMatricesNotEqualDifferentABCD(self):
-        m = Matrix(1,0,0,1)
+        m = Matrix(1, 0, 0, 1)
         m2 = Matrix(A=1 / 2, D=2)
         self.assertNotEqual(m, m2)
Repository: ECCO-GROUP/ECCOv4-py

Issue:
'Faroe Scotland' is included in the get_available_sections() but not included in get_section_endpoints()
get_section_endpoints() returns and error for 'Faroe Scotland'. I think this is because the coordinates for this section is actually not included in the function. I assume that the info exists but was accidentally removed.

Comments:

Patch:
diff --git a/ecco_v4_py/get_section_masks.py b/ecco_v4_py/get_section_masks.py
index a03db6f..6ffa665 100644
--- a/ecco_v4_py/get_section_masks.py
+++ b/ecco_v4_py/get_section_masks.py
@@ -90,6 +90,9 @@ def get_section_endpoints(section_name):
     elif section_name == 'icelandfaroe':
         pt1 = [-16, 65]
         pt2 = [ -7, 62.5]
+    elif section_name == 'faroescotland':
+        pt1 = [-6.5, 62.5]
+        pt2 = [-4, 57]
     elif section_name == 'scotlandnorway':
         pt1 = [-4, 57]
         pt2 = [ 8, 62]


Test patch:
diff --git a/ecco_v4_py/test/test_section_masks.py b/ecco_v4_py/test/test_section_masks.py
new file mode 100644
index 0000000..9610842
--- /dev/null
+++ b/ecco_v4_py/test/test_section_masks.py
@@ -0,0 +1,11 @@
+
+from __future__ import division, print_function
+import ecco_v4_py as ecco
+
+
+def test_section_endpoints():
+    """Ensure that the listed available sections are actually there
+    """
+
+    for section in ecco.get_available_sections():
+        assert ecco.get_section_endpoints(section) is not None
Repository: ESSS/conda-devenv

Issue:
0.9.3 broken: no longer generates activate/deactivate scripts
#46 introduced a bug: `conda-devenv` now calls `conda_env.main` directly, which probably calls `sys.exit()`, which skips activate/deactivate scripts generation.

Comments:

Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index 608aaa0..f9fafd4 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -3,6 +3,12 @@ History
 =======
 
 
+0.9.5 (2017-04-24)
+------------------
+
+* Handle ``None`` correctly, which actually fixes (`#49`_).
+
+
 0.9.4 (2017-04-20)
 ------------------
 
diff --git a/conda_devenv/devenv.py b/conda_devenv/devenv.py
index 16d174c..44df72e 100644
--- a/conda_devenv/devenv.py
+++ b/conda_devenv/devenv.py
@@ -373,7 +373,7 @@ def main(args=None):
 
     # Call conda-env update
     retcode = __call_conda_env_update(args, output_filename)
-    if retcode != 0:
+    if retcode:
         return retcode
 
     if is_devenv_input_file:


Test patch:
diff --git a/tests/test_main.py b/tests/test_main.py
index 4f0db10..feb2425 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -21,16 +21,20 @@ def patch_conda_calls(mocker):
     ('environment.devenv.yml', 1),
     ('environment.yml', 0),
 ])
+@pytest.mark.parametrize('return_none', [True, False])
 @pytest.mark.usefixtures('patch_conda_calls')
-def test_handle_input_file(tmpdir, input_name, write_scripts_call_count):
+def test_handle_input_file(tmpdir, input_name, write_scripts_call_count, return_none):
     """
     Test how conda-devenv handles input files: devenv.yml and pure .yml files.
     """
     argv = []
     def call_conda_mock():
         argv[:] = sys.argv[:]
-        # simulate that we actually called conda's main, which calls sys.exit()
-        sys.exit(0)
+        # conda's env main() function sometimes returns None and other times raises SystemExit
+        if return_none:
+            return None
+        else:
+            sys.exit(0)
 
     devenv._call_conda.side_effect = call_conda_mock
Repository: EdinburghGenomics/EGCG-Core

Issue:
Canis lupus familiaris NCBI query returns None
Because _C. l. familiaris_ has `subspecies` in its efetch, the regex system in `fetch_from_eutils` breaks down. We should query the XML more robustly.

Comments:

Patch:
diff --git a/egcg_core/ncbi.py b/egcg_core/ncbi.py
index 13f74d6..69cc44c 100644
--- a/egcg_core/ncbi.py
+++ b/egcg_core/ncbi.py
@@ -76,7 +76,7 @@ def _fetch_from_eutils(species):
         rank = None
         if match:
             rank = match.group(1)
-        if rank == 'species':
+        if rank in ['species', 'subspecies']:
             scientific_name = common_name = None
             match = re.search('<ScientificName>(.+?)</ScientificName>', r.text, re.MULTILINE)
             if match:


Test patch:
diff --git a/tests/test_ncbi.py b/tests/test_ncbi.py
index ef931bb..af10556 100644
--- a/tests/test_ncbi.py
+++ b/tests/test_ncbi.py
@@ -24,6 +24,11 @@ def test_fetch_from_eutils():
         <OtherNames><CommonName>a common name</CommonName></OtherNames>
         <Rank>species</Rank>
     '''
+    ncbi_fetch_data_sub_spe = '''
+        <ScientificName>Genus species</ScientificName>
+        <OtherNames><CommonName>a common name</CommonName></OtherNames>
+        <Rank>subspecies</Rank>
+    '''
 
     patched_get = patch(
         'egcg_core.ncbi.requests.get',
@@ -34,7 +39,15 @@ def test_fetch_from_eutils():
             FakeRestResponse(content=ncbi_fetch_data)
         )
     )
-
+    patched_get2 = patch(
+        'egcg_core.ncbi.requests.get',
+        side_effect=(
+            FakeRestResponse(content=ncbi_search_data),
+            FakeRestResponse(content=ncbi_fetch_data_sub_spe),
+            FakeRestResponse(content=ncbi_fetch_data_sub_spe),
+            FakeRestResponse(content=ncbi_fetch_data_sub_spe)
+        )
+    )
     with patched_get as mocked_get:
         obs = fetch_from_eutils('a_species')
         assert obs == ('1337', 'Genus species', 'a common name')
@@ -46,6 +59,10 @@ def test_fetch_from_eutils():
             'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi',
             params={'db': 'Taxonomy', 'id': '1337'}
         )
+    with patched_get2:
+        obs = fetch_from_eutils('a_species')
+        assert obs == ('1337', 'Genus species', 'a common name')
+
 
 
 def test_cache():
Repository: EdinburghGenomics/EGCG-Core

Issue:
Failure to register for archiving cause pipeline crash
We should make the registering for archiving more robust by sleeping trying again to register the file after 1 second.
https://github.com/EdinburghGenomics/EGCG-Core/blob/master/egcg_core/archive_management.py#L92
This raising can cause Analysis Driver to crash at the end of the processing rather randomly.


Comments:

Patch:
diff --git a/egcg_core/archive_management.py b/egcg_core/archive_management.py
index 3437925..58c5eb9 100644
--- a/egcg_core/archive_management.py
+++ b/egcg_core/archive_management.py
@@ -1,6 +1,8 @@
 import os
 import re
 import subprocess
+from time import sleep
+
 from egcg_core.app_logging import logging_default as log_cfg
 from egcg_core.exceptions import EGCGError
 
@@ -83,13 +85,18 @@ def release_file_from_lustre(file_path):
         return True
 
 
-def register_for_archiving(file_path):
+def register_for_archiving(file_path, strict=False):
     if is_register_for_archiving(file_path):
         return True
     cmd = 'lfs hsm_archive %s' % file_path
     val = _get_stdout(cmd)
     if val is None or not is_register_for_archiving(file_path):
-        raise ArchivingError('Registering %s for archiving to tape failed' % file_path)
+        if strict:
+            raise ArchivingError('Registering %s for archiving to tape failed' % file_path)
+        # Registering for archive can sometime take time so give it a second
+        sleep(1)
+        return register_for_archiving(filter, strict=True)
+
     return True
 
 


Test patch:
diff --git a/tests/test_archive_management.py b/tests/test_archive_management.py
index c087706..5d45646 100644
--- a/tests/test_archive_management.py
+++ b/tests/test_archive_management.py
@@ -76,7 +76,7 @@ class TestArchiveManagement(TestEGCG):
                        '',
                        'testfile: (0x00000001)',
                     ]) as get_stdout:
-            self.assertRaises(ArchivingError, register_for_archiving, 'testfile')
+            self.assertRaises(ArchivingError, register_for_archiving, 'testfile', True)
             assert get_stdout.call_count == 3
             assert get_stdout.call_args_list[1][0] == ('lfs hsm_archive testfile',)