Skip to content

Commit c8d00f2

Browse files
authored
Python: updated partial APIs naming (#8826)
* `update_fields(clear: bool, ...)` -> `from_fields(clear_unset: bool, ...)` * `clear_fields()` -> `cleared()` * `cleared()` is not implemented by forwarding to `from_fields(clear_unset=True)` This does not cover implementing the constructors in terms of `from_fields()`. If that happens at all, this will be in one or more follow-ups. --- * Part of #8822
1 parent 7293f69 commit c8d00f2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+391
-897
lines changed

crates/build/re_types_builder/src/codegen/python/mod.rs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,7 +2537,7 @@ fn quote_partial_update_methods(reporter: &Reporter, obj: &Object, objects: &Obj
25372537
doc_string_lines.push("\n".to_owned());
25382538
doc_string_lines.push("Parameters".to_owned());
25392539
doc_string_lines.push("----------".to_owned());
2540-
doc_string_lines.push("clear:".to_owned());
2540+
doc_string_lines.push("clear_unset:".to_owned());
25412541
doc_string_lines
25422542
.push(" If true, all unspecified fields will be explicitly cleared.".to_owned());
25432543
for doc in parameter_docs {
@@ -2546,24 +2546,13 @@ fn quote_partial_update_methods(reporter: &Reporter, obj: &Object, objects: &Obj
25462546
};
25472547
let doc_block = indent::indent_by(12, quote_doc_lines(doc_string_lines));
25482548

2549-
let field_clears = obj
2550-
.fields
2551-
.iter()
2552-
.map(|field| {
2553-
let field_name = field.snake_case_name();
2554-
format!("{field_name}=[],")
2555-
})
2556-
.collect_vec()
2557-
.join("\n");
2558-
let field_clears = indent::indent_by(12, field_clears);
2559-
25602549
unindent(&format!(
25612550
r#"
25622551
@classmethod
2563-
def update_fields(
2552+
def from_fields(
25642553
cls,
25652554
*,
2566-
clear: bool = False,
2555+
clear_unset: bool = False,
25672556
{parameters},
25682557
) -> {name}:
25692558
{doc_block}
@@ -2573,7 +2562,7 @@ fn quote_partial_update_methods(reporter: &Reporter, obj: &Object, objects: &Obj
25732562
{kwargs},
25742563
}}
25752564
2576-
if clear:
2565+
if clear_unset:
25772566
kwargs = {{k: v if v is not None else [] for k, v in kwargs.items()}} # type: ignore[misc]
25782567
25792568
inst.__attrs_init__(**kwargs)
@@ -2583,13 +2572,9 @@ fn quote_partial_update_methods(reporter: &Reporter, obj: &Object, objects: &Obj
25832572
return inst
25842573
25852574
@classmethod
2586-
def clear_fields(cls) -> {name}:
2575+
def cleared(cls) -> {name}:
25872576
"""Clear all the fields of a `{name}`."""
2588-
inst = cls.__new__(cls)
2589-
inst.__attrs_init__(
2590-
{field_clears}
2591-
)
2592-
return inst
2577+
return cls.from_fields(clear_unset=True)
25932578
"#
25942579
))
25952580
}

docs/snippets/all/archetypes/mesh3d_partial_updates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
factors = np.abs(np.sin(np.arange(1, 300, dtype=np.float32) * 0.04))
2323
for i, factor in enumerate(factors):
2424
rr.set_time_sequence("frame", i)
25-
rr.log("triangle", rr.Mesh3D.update_fields(vertex_positions=vertex_positions * factor))
25+
rr.log("triangle", rr.Mesh3D.from_fields(vertex_positions=vertex_positions * factor))

docs/snippets/all/archetypes/points3d_partial_updates.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
radii = [0.6 if n < i else 0.2 for n in range(0, 10)]
1515

1616
rr.set_time_sequence("frame", i)
17-
rr.log("points", rr.Points3D.update_fields(radii=radii, colors=colors))
17+
rr.log("points", rr.Points3D.from_fields(radii=radii, colors=colors))
1818

1919
rr.set_time_sequence("frame", 20)
20-
rr.log("points", rr.Points3D.update_fields(clear=True, positions=positions, radii=0.3))
20+
rr.log("points", rr.Points3D.from_fields(clear_unset=True, positions=positions, radii=0.3))

docs/snippets/all/archetypes/transform3d_partial_updates.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def truncated_radians(deg: float) -> float:
2323
rad = truncated_radians(deg * 4)
2424
rr.log(
2525
"box",
26-
rr.Transform3D.update_fields(
26+
rr.Transform3D.from_fields(
2727
# TODO(cmc): we should have access to all the fields of the extended constructor too.
2828
rotation_axis_angle=rr.RotationAxisAngle(axis=[0.0, 1.0, 0.0], radians=rad),
2929
),
@@ -33,15 +33,15 @@ def truncated_radians(deg: float) -> float:
3333
for t in range(51):
3434
rr.log(
3535
"box",
36-
rr.Transform3D.update_fields(translation=[0, 0, t / 10.0]),
36+
rr.Transform3D.from_fields(translation=[0, 0, t / 10.0]),
3737
)
3838

3939
# Update only the rotation of the box.
4040
for deg in range(46):
4141
rad = truncated_radians((deg + 45) * 4)
4242
rr.log(
4343
"box",
44-
rr.Transform3D.update_fields(
44+
rr.Transform3D.from_fields(
4545
# TODO(cmc): we should have access to all the fields of the extended constructor too.
4646
rotation_axis_angle=rr.RotationAxisAngle(axis=[0.0, 1.0, 0.0], radians=rad),
4747
),
@@ -50,5 +50,5 @@ def truncated_radians(deg: float) -> float:
5050
# Clear all of the box's attributes, and reset its axis length.
5151
rr.log(
5252
"box",
53-
rr.Transform3D.update_fields(clear=True, axis_length=15),
53+
rr.Transform3D.from_fields(clear_unset=True, axis_length=15),
5454
)

docs/snippets/all/tutorials/data_out.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
# log a `Label` component to the face bounding box entity
4040
target_entity = "/video/detector/faces/0/bbox"
41-
rr.log(target_entity, rr.Boxes2D.update_fields(show_labels=True), static=True)
41+
rr.log(target_entity, rr.Boxes2D.from_fields(show_labels=True), static=True)
4242
rr.send_columns(
4343
target_entity,
4444
indexes=[rr.TimeSequenceColumn("frame_nr", df["frame_nr"])],

examples/python/air_traffic_data/air_traffic_data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,12 @@ def log_position_and_altitude(self, df: polars.DataFrame, icao_id: str) -> None:
318318
color = rr.components.Color.from_string(entity_path)
319319
rr.log(
320320
entity_path,
321-
rr.Points3D.update_fields(colors=color),
321+
rr.Points3D.from_fields(colors=color),
322322
# TODO(cmc): That would be UB right now (and doesn't matter as long as we are on the untagged index).
323-
# rr.GeoPoints.update_fields(colors=color),
323+
# rr.GeoPoints.from_fields(colors=color),
324324
static=True,
325325
)
326-
rr.log(entity_path + "/barometric_altitude", rr.SeriesLine.update_fields(color=color), static=True)
326+
rr.log(entity_path + "/barometric_altitude", rr.SeriesLine.from_fields(color=color), static=True)
327327
self._position_indicators.add(icao_id)
328328

329329
timestamps = rr.TimeSecondsColumn("unix_time", df["timestamp"].to_numpy())

examples/python/detect_and_track_objects/detect_and_track_objects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def log_tracked(self) -> None:
213213
),
214214
)
215215
else:
216-
rr.log(f"video/tracked/{self.tracking_id}", rr.Boxes2D.clear_fields())
216+
rr.log(f"video/tracked/{self.tracking_id}", rr.Boxes2D.cleared())
217217

218218
def update_with_detection(self, detection: Detection, bgr: cv2.typing.MatLike) -> None:
219219
self.num_recent_undetected_frames = 0

examples/python/drone_lidar/drone_lidar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def log_lidar_data() -> None:
119119
rr.log(
120120
"/lidar",
121121
# negative radii are interpreted in UI units (instead of scene units)
122-
rr.Points3D.update_fields(colors=(128, 128, 255), radii=-0.1),
122+
rr.Points3D.from_fields(colors=(128, 128, 255), radii=-0.1),
123123
static=True,
124124
)
125125

@@ -137,7 +137,7 @@ def log_drone_trajectory() -> None:
137137

138138
rr.log(
139139
"/drone",
140-
rr.Points3D.update_fields(colors=(255, 0, 0), radii=0.5),
140+
rr.Points3D.from_fields(colors=(255, 0, 0), radii=0.5),
141141
static=True,
142142
)
143143

examples/python/incremental_logging/incremental_logging.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# Only log colors and radii once.
2424
# Logging as static would also work (i.e. `static=True`).
2525
rr.set_time_sequence("frame_nr", 0)
26-
rr.log("points", rr.Points3D.update_fields(colors=0xFF0000FF, radii=0.1))
26+
rr.log("points", rr.Points3D.from_fields(colors=0xFF0000FF, radii=0.1))
2727
2828
rng = default_rng(12345)
2929
@@ -32,7 +32,7 @@
3232
# They will automatically re-use the colors and radii logged at the beginning.
3333
for i in range(10):
3434
rr.set_time_sequence("frame_nr", i)
35-
rr.log("points", rr.Points3D.update_fields(positions=rng.uniform(-5, 5, size=[10, 3])))
35+
rr.log("points", rr.Points3D.from_fields(positions=rng.uniform(-5, 5, size=[10, 3])))
3636
```
3737
3838
Move the time cursor around, and notice how the colors and radii from frame 0 are still picked up by later frames, while the points themselves keep changing every frame.
@@ -47,7 +47,7 @@
4747
# Only log colors and radii once.
4848
# Logging as static would also work (i.e. `static=True`).
4949
rr.set_time_sequence("frame_nr", 0)
50-
rr.log("points", rr.Points3D.update_fields(colors=0xFF0000FF, radii=0.1))
50+
rr.log("points", rr.Points3D.from_fields(colors=0xFF0000FF, radii=0.1))
5151

5252
rng = default_rng(12345)
5353

@@ -56,6 +56,6 @@
5656
# They will automatically re-use the colors and radii logged at the beginning.
5757
for i in range(10):
5858
rr.set_time_sequence("frame_nr", i)
59-
rr.log("points", rr.Points3D.update_fields(positions=rng.uniform(-5, 5, size=[10, 3])))
59+
rr.log("points", rr.Points3D.from_fields(positions=rng.uniform(-5, 5, size=[10, 3])))
6060

6161
rr.script_teardown(args)

rerun_py/rerun_sdk/rerun/archetypes/annotation_context.py

Lines changed: 6 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rerun_py/rerun_sdk/rerun/archetypes/arrows2d.py

Lines changed: 6 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rerun_py/rerun_sdk/rerun/archetypes/arrows3d.py

Lines changed: 6 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)