forked from rerun-io/rerun
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve edge-cases and warn on ambiguity for Rgba32 datatype (rerun-i…
…o#8054) ### What - Resolves: rerun-io#8035 - Makes it so lists of ints are generally assumed to be packed colors unless they are length 3 or 4 - Warns when passing a length 3 or 4 list of colors that uses values outside of the u8 range. - Preserves the old functionality when explicitly passing an np.array of the right type. The previous offending code: ```python import rerun as rr rr.init("rerun_example_colorbad", spawn=True) point = [[0, 0, 0]] colors = [0x00FF00FF] # green for n in range(30): rr.log("points3d", rr.Points3D(positions=point * n, colors=colors * n)) ``` Now works, but produces a warning: ``` /home/jleibs/colorbad.py:11: RerunWarning: Ambiguous input for colors of length 4. If using 0xRRGGBBAA values, please wrap as np.array with dtype=np.uint32 rr.log("points3d", rr.Points3D(positions=point * n, colors=colors * n)) ``` ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested the web demo (if applicable): * Using examples from latest `main` build: [rerun.io/viewer](https://rerun.io/viewer/pr/8054?manifest_url=https://app.rerun.io/version/main/examples_manifest.json) * Using full set of examples from `nightly` build: [rerun.io/viewer](https://rerun.io/viewer/pr/8054?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG * [x] If applicable, add a new check to the [release checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)! * [x] If have noted any breaking changes to the log API in `CHANGELOG.md` and the migration guide - [PR Build Summary](https://build.rerun.io/pr/8054) - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html) To run all checks from `main`, comment on the PR with `@rerun-bot full-check`.
- Loading branch information
Showing
3 changed files
with
168 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
from __future__ import annotations | ||
|
||
import numpy as np | ||
import pytest | ||
import rerun as rr | ||
from rerun.datatypes import Rgba32ArrayLike, Rgba32Batch | ||
from rerun.error_utils import RerunWarning | ||
|
||
CASES: list[tuple[Rgba32ArrayLike, Rgba32ArrayLike]] = [ | ||
( | ||
[], | ||
[], | ||
), | ||
( | ||
0x12345678, | ||
[0x12345678], | ||
), | ||
( | ||
[0x12345678], | ||
[0x12345678], | ||
), | ||
( | ||
[[0x12345678]], | ||
[0x12345678], | ||
), | ||
( | ||
[1, 2, 3], | ||
[0x010203FF], | ||
), | ||
( | ||
[[1, 2, 3]], | ||
[0x010203FF], | ||
), | ||
( | ||
[1.0, 1.0, 1.0], | ||
[0xFFFFFFFF], | ||
), | ||
( | ||
[[1.0, 1.0, 1.0]], | ||
[0xFFFFFFFF], | ||
), | ||
( | ||
[1, 2, 3, 4], | ||
[0x01020304], | ||
), | ||
( | ||
[[1, 2, 3, 4]], | ||
[0x01020304], | ||
), | ||
( | ||
[0x11000000, 0x00220000], | ||
[0x11000000, 0x00220000], | ||
), | ||
( | ||
[[1, 2, 3, 4], [5, 6, 7, 8]], | ||
[0x01020304, 0x05060708], | ||
), | ||
( | ||
[1, 2, 3, 4, 5, 6, 7, 8], | ||
[1, 2, 3, 4, 5, 6, 7, 8], | ||
), | ||
( | ||
np.array([1, 2, 3, 4, 5, 6, 7, 8], dtype=np.uint8), | ||
[0x01020304, 0x05060708], | ||
), | ||
( | ||
[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]], | ||
[0x01020304, 0x05060708, 0x090A0B0C], | ||
), | ||
( | ||
np.array([0x11000000, 0x00220000, 0x00003300], dtype=np.uint32), | ||
[0x11000000, 0x00220000, 0x00003300], | ||
), | ||
] | ||
|
||
|
||
def test_rgba() -> None: | ||
for input, expected in CASES: | ||
data = Rgba32Batch(input) | ||
assert data.as_arrow_array().to_pylist() == expected | ||
|
||
|
||
AMBIGUOUS_CASES: list[tuple[Rgba32ArrayLike, Rgba32ArrayLike]] = [ | ||
( | ||
[0x11000000, 0x00220000, 0x00003300], | ||
[0x11000000, 0x00220000, 0x00003300], | ||
), | ||
( | ||
[0x11000000, 0x00220000, 0x00003300, 0x00000044], | ||
[0x11000000, 0x00220000, 0x00003300, 0x00000044], | ||
), | ||
] | ||
|
||
|
||
def test_ambiguous_rgba() -> None: | ||
rr.init("rerun_example_ambiguous_rgba", strict=False) | ||
for input, expected in AMBIGUOUS_CASES: | ||
with pytest.warns(RerunWarning) as warnings: | ||
data = Rgba32Batch(input) | ||
assert data.as_arrow_array().to_pylist() == expected | ||
assert len(warnings) == 1 |