Repository: napari-threedee/napari-threedee (language: python)

Issue:
Creating empty points layers from N3DPoints can cause invalid layers
```
│ ╭───────────────────────────── locals ──────────────────────────────╮                            │
│ │ metadata = {'n3d_metadata': {'annotation_type': 'points'}}        │                            │
│ │     self = N3dPoints(data=array([], shape=(1, 0), dtype=float32)) │                            │
│ ╰───────────────────────────────────────────────────────────
ValueError: operands could not be broadcast together with shapes (2,) (0,) 
```

This error pops up when adding the layer to the viewer somewhere in update thumbnail - should ensure layer has an ndim of 3 or something :)


Discussion / hints:

Fix patch:
diff --git a/src/napari_threedee/data_models/points.py b/src/napari_threedee/data_models/points.py
index 171316e..bfb2923 100644
--- a/src/napari_threedee/data_models/points.py
+++ b/src/napari_threedee/data_models/points.py
@@ -50,4 +50,7 @@ def to_n3d_zarr(self, path: os.PathLike) -> None:
 
     @validator('data', pre=True)
     def ensure_2d_float32_array(cls, value):
-        return np.atleast_2d(np.asarray(value, dtype=np.float32))
+        data = np.atleast_2d(np.asarray(value, dtype=np.float32))
+        if data.shape[-1] == 0:
+            data = np.zeros(shape=(0, 3))
+        return data


Test patch:
diff --git a/src/napari_threedee/data_models/_tests/test_points.py b/src/napari_threedee/data_models/_tests/test_points.py
new file mode 100644
index 0000000..6ee1393
--- /dev/null
+++ b/src/napari_threedee/data_models/_tests/test_points.py
@@ -0,0 +1,6 @@
+import napari_threedee as n3d
+
+
+def test_empty_points():
+    points = n3d.data_models.N3dPoints(data=[])
+    assert points.data.shape == (0, 3)