From 0e2a24f56398297aee2cc93d58b921cb9399add8 Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Wed, 26 Jul 2023 01:33:23 +0200 Subject: [PATCH] Handle empty arrays --- rerun_py/rerun_sdk/rerun/components/quaternion.py | 2 +- rerun_py/rerun_sdk/rerun/components/vec.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rerun_py/rerun_sdk/rerun/components/quaternion.py b/rerun_py/rerun_sdk/rerun/components/quaternion.py index 443b63e9abcfc..e6c0b5cb705e7 100644 --- a/rerun_py/rerun_sdk/rerun/components/quaternion.py +++ b/rerun_py/rerun_sdk/rerun/components/quaternion.py @@ -29,7 +29,7 @@ def __array__(self) -> npt.NDArray[np.float32]: class QuaternionArray(pa.ExtensionArray): # type: ignore[misc] def from_numpy(array: npt.NDArray[np.float32]) -> QuaternionArray: """Build a `QuaternionArray` from an Nx4 numpy array.""" - assert array.shape[1] == 4 + assert len(array) == 0 or array.shape[1] == 4 storage = pa.FixedSizeListArray.from_arrays(array.flatten(), type=QuaternionType.storage_type) # TODO(john) enable extension type wrapper # return cast(QuaternionArray, pa.ExtensionArray.from_storage(QuaternionType(), storage)) diff --git a/rerun_py/rerun_sdk/rerun/components/vec.py b/rerun_py/rerun_sdk/rerun/components/vec.py index 5c222159cc5c5..eeca3fb9a3380 100644 --- a/rerun_py/rerun_sdk/rerun/components/vec.py +++ b/rerun_py/rerun_sdk/rerun/components/vec.py @@ -17,7 +17,7 @@ class Vec2DArray(pa.ExtensionArray): # type: ignore[misc] def from_numpy(array: npt.NDArray[np.float32]) -> Vec2DArray: """Build a `Vec2DArray` from an Nx2 numpy array.""" - assert array.shape[1] == 2 + assert len(array) == 0 or array.shape[1] == 2 storage = pa.FixedSizeListArray.from_arrays(array.flatten(), type=Vec2DType.storage_type) # TODO(john) enable extension type wrapper # return cast(Vec2DArray, pa.ExtensionArray.from_storage(Vec2DType(), storage)) @@ -32,7 +32,7 @@ def from_numpy(array: npt.NDArray[np.float32]) -> Vec2DArray: class Vec3DArray(pa.ExtensionArray): # type: ignore[misc] def from_numpy(array: npt.NDArray[np.float32]) -> Vec3DArray: """Build a `Vec3DArray` from an Nx3 numpy array.""" - assert array.shape[1] == 3 + assert len(array) == 0 or array.shape[1] == 3 storage = pa.FixedSizeListArray.from_arrays(array.flatten(), type=Vec3DType.storage_type) # TODO(john) enable extension type wrapper # return cast(Vec3DArray, pa.ExtensionArray.from_storage(Vec3DType(), storage))