nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: pygfx/pygfx
Pull request #544 (2023-06-01 14:36:57)

Fix that the polyhedron indices array was 3 times too long
Detected while working on unit tests for the morph-tool-logic that validates the mesh 🥳 


Patch:
diff --git a/pygfx/geometries/_polyhedron.py b/pygfx/geometries/_polyhedron.py
index 1b509d7..63da65e 100644
--- a/pygfx/geometries/_polyhedron.py
+++ b/pygfx/geometries/_polyhedron.py
@@ -373,7 +373,7 @@ def polyhedron_geometry(
     faces *= radius
 
     # technically if meshmaterial didn't require an index buffer we could leave this out
-    indices = np.arange(positions.size, dtype=np.int32).reshape(-1, 3)
+    indices = np.arange(positions.shape[0], dtype=np.int32).reshape(-1, 3)
 
     return Geometry(
         indices=indices,


Test patch:
diff --git a/tests/geometries/test_polyhedron.py b/tests/geometries/test_polyhedron.py
index f24d763..521de62 100644
--- a/tests/geometries/test_polyhedron.py
+++ b/tests/geometries/test_polyhedron.py
@@ -26,8 +26,9 @@ def test_polyhedrons():
         assert g.indices.data.dtype == np.int32
         assert g.positions.data.shape == (nr_faces * 3, 3)
         assert g.positions.data.shape == g.normals.data.shape
-        assert g.positions.data.shape == g.indices.data.shape
         assert g.positions.data.shape[:-1] + (2,) == g.texcoords.data.shape
+        assert g.indices.data.size == g.positions.data.shape[0]
+        assert g.indices.data.size == len(set(g.indices.data.flat))
         assert np.allclose(np.linalg.norm(g.positions.data, axis=-1), 1)
Repository: pygfx/pygfx
Pull request #1062 (2025-04-01 19:53:09)

Don't throw AttributeError when calling dict attributes
This makes Geometry behave more like a proper dict.

berendkleinhaneveld: I can imagine that you would not want to support calling any other methods on Store objects, so please let me know what you think.
I encountered this `AttributeError` in collagraph/observ when a geometry is part of a reactive state object. It calls the `values()` method on any dict within the reactive state. I could also imagine just adding a try/except there instead of this PR.

Patch:
diff --git a/pygfx/utils/trackable.py b/pygfx/utils/trackable.py
index b6e3d86..08c5c7f 100644
--- a/pygfx/utils/trackable.py
+++ b/pygfx/utils/trackable.py
@@ -54,9 +54,8 @@ there is no persistent knowledge of hierarchy.
 
 """
 
-import weakref
 import threading
-
+import weakref
 
 global_id_counter = 0
 global_lock = threading.RLock()
@@ -150,7 +149,7 @@ class Store(dict):
             value = self[key]
             return value
         except KeyError:
-            raise AttributeError(key) from None
+            return dict.__getattribute__(self, key)
         finally:
             if global_context:
                 global_context.tracker._track_get(


Test patch:
diff --git a/tests/geometries/test_geometry.py b/tests/geometries/test_geometry.py
index 9be8ba1..e95bc29 100644
--- a/tests/geometries/test_geometry.py
+++ b/tests/geometries/test_geometry.py
@@ -1,7 +1,8 @@
 import numpy as np
-import pygfx as gfx
 import pytest
 
+import pygfx as gfx
+
 
 def test_different_data_types():
     # Numpy array, let's do float16 while we're at it
@@ -48,3 +49,9 @@ def test_check_positions():
     a = np.zeros((10, 2), np.float32)
     with pytest.raises(ValueError):
         gfx.Geometry(positions=a)
+
+
+def test_check_common_dict_attributes():
+    g = gfx.Geometry(positions=[[0, 1, 0], [1, 0, 1]])
+    assert "positions" in g.keys()
+    assert len(g.keys()) == len(g.values())