Skip to content

Commit

Permalink
Handle empty arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
jleibs committed Jul 25, 2023
1 parent c3cf716 commit 0e2a24f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion rerun_py/rerun_sdk/rerun/components/quaternion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions rerun_py/rerun_sdk/rerun/components/vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand Down

0 comments on commit 0e2a24f

Please sign in to comment.