Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused num_instances() method #8702

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions docs/content/reference/migration/migration-0-22.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
title: Migrating from 0.20 to 0.21
order: 989
title: Migrating from 0.21 to 0.22
order: 988
---

### Previously deprecated `DisconnectedSpace` archetype/component got now removed.
### Previously deprecated `DisconnectedSpace` archetype/component got now removed

The deprecated `DisconnectedSpace` archetype and `DisconnectedSpace` component have been removed.
To achieve the same effect, you can log any of the following "invalid" transforms:
Expand All @@ -16,3 +16,12 @@
This led to a lot of complexity and often broke or caused confusion (see https://github.com/rerun-io/rerun/issues/6817, https://github.com/rerun-io/rerun/issues/4465, https://github.com/rerun-io/rerun/issues/4221).
By now, explicit blueprints offer a better way to express which views should be spawned and what content they should query.
(you can learn more about blueprints [here](https://rerun.io/docs/getting-started/configure-the-viewer/through-code-tutorial)).


### Removed `num_instances` keyword argument to `rr.log_components()`

For historical reasons, the `rr.log_components()` function of the Python SDK accepts an optional, keyword-ony argument `num_instances`.

Check warning on line 23 in docs/content/reference/migration/migration-0-22.md

View workflow job for this annotation

GitHub Actions / Checks / Spell Check

"ony" should be "only" or "on" or "one".
It was no longer used for several releases, so we removed it.

**Note**: although `rr.log_components()` is technically a public API, it is undocumented, and we discourage using it.
For logging custom components, use [`rr.AnyValue`](https://ref.rerun.io/docs/python/main/common/custom_data/#rerun.AnyValues) and [`rr.AnyBatchValue`](https://ref.rerun.io/docs/python/main/common/custom_data/#rerun.AnyBatchValue).
24 changes: 1 addition & 23 deletions rerun_py/rerun_sdk/rerun/_baseclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,7 @@ def as_arrow_array(self) -> pa.Array:


class AsComponents(Protocol):
"""
Describes interface for interpreting an object as a bundle of Components.

Note: the `num_instances()` function is an optional part of this interface. The method does not need to be
implemented as it is only used after checking for its existence. (There is unfortunately no way to express this
correctly with the Python typing system, see <https://github.com/python/typing/issues/601>).
"""
"""Describes interface for interpreting an object as a bundle of Components."""

def as_component_batches(self) -> Iterable[ComponentBatchLike]:
"""
Expand Down Expand Up @@ -198,22 +192,6 @@ def indicator(cls) -> ComponentBatchLike:

return IndicatorComponentBatch(cls.archetype_name())

def num_instances(self) -> int:
"""
The number of instances that make up the batch.

Part of the `AsComponents` logging interface.
"""
num_instances = 0
for fld in fields(type(self)):
if "component" in fld.metadata:
try:
num_instances = max(num_instances, len(getattr(self, fld.name)))
except TypeError: # Happens for indicator batches.
num_instances = max(num_instances, 1)

return num_instances

def as_component_batches(self) -> Iterable[ComponentBatchLike]:
"""
Return all the component batches that make up the archetype.
Expand Down
16 changes: 1 addition & 15 deletions rerun_py/rerun_sdk/rerun/_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,9 @@ def log(
f"but got {type(entity)} instead."
)

if hasattr(entity, "num_instances"):
num_instances = entity.num_instances()
else:
num_instances = None

log_components(
entity_path=entity_path,
components=components,
num_instances=num_instances,
static=static,
recording=recording, # NOLINT
)
Expand All @@ -191,7 +185,6 @@ def log_components(
entity_path: str | list[str],
components: Iterable[ComponentBatchLike],
*,
num_instances: int | None = None,
timeless: bool = False,
static: bool = False,
recording: RecordingStream | None = None,
Expand All @@ -216,11 +209,7 @@ def log_components(
See <https://www.rerun.io/docs/concepts/entity-path> for more on entity paths.

components:
A collection of `ComponentBatchLike` objects that

num_instances:
Optional. The number of instances in each batch. If not provided, the max of all
components will be used instead.
A collection of `ComponentBatchLike` objects.

timeless:
Deprecated. Refer to `static` instead.
Expand Down Expand Up @@ -263,9 +252,6 @@ def log_components(
descriptors = [comp.component_descriptor() for comp in components]
arrow_arrays = [comp.as_arrow_array() for comp in components]

if num_instances is None:
num_instances = max(len(arr) for arr in arrow_arrays)

if isinstance(entity_path, list):
entity_path = bindings.new_entity_path([str(part) for part in entity_path])

Expand Down
4 changes: 0 additions & 4 deletions rerun_py/rerun_sdk/rerun/components/view_coordinates_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ def as_component_batches(self) -> Iterable[ComponentBatchLike]:

return ViewCoordinates(cast(ViewCoordinatesComponent, self)).as_component_batches()

def num_instances(self) -> int:
# Always a mono-component
return 1

# <BEGIN_GENERATED:declarations>
# This section is generated by running `scripts/generate_view_coordinate_defs.py --python`
# The following declarations are replaced in `deferred_patch_class`.
Expand Down
Loading