nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: pydap/pydap
Pull request #79 (2017-03-24 17:59:01)

Fix attributes parser error raised in #75
This PR solves #75. It introduces a more stringent DAS test.


Patch:
diff --git a/src/pydap/parsers/das.py b/src/pydap/parsers/das.py
index 3bf80f2..91b0540 100644
--- a/src/pydap/parsers/das.py
+++ b/src/pydap/parsers/das.py
@@ -124,9 +124,16 @@ def add_attributes(dataset, attributes):
             nested = reduce(
                 operator.getitem, [attributes] + var.id.split('.')[:-1])
             k = var.id.split('.')[-1]
-            var.attributes.update(nested.pop(k))
+            value = nested.pop(k)
         except KeyError:
             pass
+        else:
+            try:
+                var.attributes.update(value)
+            except (TypeError, ValueError):
+                # This attribute should be given to the parent.
+                # Keep around:
+                nested.update({k: value})
 
     # add attributes that don't belong to any child
     for k, v in attributes.items():


Test patch:
diff --git a/src/pydap/tests/test_parsers_das.py b/src/pydap/tests/test_parsers_das.py
index d1608d1..69aedee 100644
--- a/src/pydap/tests/test_parsers_das.py
+++ b/src/pydap/tests/test_parsers_das.py
@@ -20,8 +20,18 @@ DAS = """Attributes {
     meta {
         String debug 1;
     }
+    SPEH {
+        Int debug 1;
+        Int TIME 0;
+        Float32 COADSX 1e20;
+        String COADSY "zero";
+    }
 }"""
 
+# It is important to add attributes that have the same
+# name as the dimensions of SPEH. This is an edge
+# case that can break the das parser.
+
 
 class TestParseDAS(unittest.TestCase):
 
@@ -52,3 +62,10 @@ class TestParseDAS(unittest.TestCase):
     def test_meta_attributes(self):
         """Test attributes not associated with any variables."""
         self.assertEqual(self.dataset.meta, {"debug": "1"})
+
+    def test_SPEH_attributes(self):
+        """Test attributes not associated with any variables."""
+        self.assertEqual(self.dataset.SPEH.debug, 1)
+        self.assertEqual(self.dataset.SPEH.attributes['TIME'], 0)
+        self.assertEqual(self.dataset.SPEH.attributes['COADSX'], 1e20)
+        self.assertEqual(self.dataset.SPEH.attributes['COADSY'], "zero")