Skip to content

Commit

Permalink
tests and extensions for components.DrawOrder
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Jun 13, 2023
1 parent 75f268d commit 8a82d28
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
17 changes: 17 additions & 0 deletions rerun_py/rerun_sdk/rerun2/components/draw_order_ext.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from __future__ import annotations

from typing import Any, Sequence

import numpy as np
import pyarrow as pa


class DrawOrderArrayExt:
@staticmethod
def _from_similar(data: Any | None, *, mono: type, mono_aliases: type, many: type, many_aliases: type, arrow: type):
if isinstance(data, Sequence) and (len(data) > 0 and isinstance(data[0], mono)):
array = np.asarray([draw_order.value for draw_order in data], np.float32)
else:
array = np.require(np.asarray(data), np.float32).flatten()

return arrow().wrap_array(pa.array(array, type=arrow().storage_type))
15 changes: 13 additions & 2 deletions rerun_py/tests/unit/test_points2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,30 +64,41 @@ def test_points2d() -> None:
],
]

draw_orders = [
None,
# DrawOrderLike: float
300,
# DrawOrderLike: DrawOrder
rrc.DrawOrder(300),
]

all_permuted_arrays = list(
itertools.product( # type: ignore[call-overload]
*[
points_arrays,
radii_arrays,
labels_arrays,
draw_orders,
]
)
)

for points, radii, labels in all_permuted_arrays:
for points, radii, labels, draw_order in all_permuted_arrays:
print(
f"rr.Points2D(\n"
f" {points}\n"
f" radii={radii}\n"
f" labels={labels}\n"
f" draw_order={draw_order}\n"
f")"
)
arch = rr.Points2D(points, radii=radii, labels=labels)
arch = rr.Points2D(points, radii=radii, labels=labels, draw_order=draw_order)
print(f"{arch}\n")

assert arch.points == rrc.Point2DArray.from_similar([[1.0, 2.0], [3.0, 4.0]])
assert arch.radii == rrc.RadiusArray.from_similar([42, 43] if radii is not None else [])
assert arch.labels == rrc.LabelArray.from_similar(["hello", "friend"] if labels is not None else [])
assert arch.draw_order == rrc.DrawOrderArray.from_similar([300] if draw_order is not None else [])


if __name__ == "__main__":
Expand Down

0 comments on commit 8a82d28

Please sign in to comment.