# DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/python/mod.rs # Based on "crates/build/re_type_definitions/rerun/encodings/range2d.def.rs". # You can extend this class by creating a "Range2DExt" class in "range2d_ext.py". from __future__ import annotations from collections.abc import Sequence from typing import Any import pyarrow as pa from attrs import define, field from .. import encodings from .._baseclasses import ( BaseBatch, ) __all__ = ["Range2D", "Range2DArrayLike", "Range2DBatch", "Range2DLike"] def _range2d__x_range__special_field_converter_override(x: encodings.Range1DLike) -> encodings.Range1D: if isinstance(x, encodings.Range1D): return x else: return encodings.Range1D(x) def _range2d__y_range__special_field_converter_override(x: encodings.Range1DLike) -> encodings.Range1D: if isinstance(x, encodings.Range1D): return x else: return encodings.Range1D(x) @define(init=False) class Range2D: """**Encoding**: An Axis-Aligned Bounding Box in 2D space, implemented as the minimum and maximum corners.""" def __init__(self: Any, x_range: encodings.Range1DLike, y_range: encodings.Range1DLike) -> None: """ Create a new instance of the Range2D encoding. Parameters ---------- x_range: The range of the X-axis (usually left and right bounds). y_range: The range of the Y-axis (usually top and bottom bounds). """ # You can define your own __init__ function as a member of Range2DExt in range2d_ext.py self.__attrs_init__(x_range=x_range, y_range=y_range) x_range: encodings.Range1D = field(converter=_range2d__x_range__special_field_converter_override) # The range of the X-axis (usually left and right bounds). # # (Docstring intentionally commented out to hide this field from the docs) y_range: encodings.Range1D = field(converter=_range2d__y_range__special_field_converter_override) # The range of the Y-axis (usually top and bottom bounds). # # (Docstring intentionally commented out to hide this field from the docs) Range2DLike = Range2D """A type alias for any Range2D-like object.""" Range2DArrayLike = Range2D | Sequence[Range2DLike] """A type alias for any Range2D-like array object.""" class Range2DBatch(BaseBatch[Range2DArrayLike]): _ARROW_DATATYPE = pa.struct([ pa.field( "x_range", pa.list_(pa.field("item", pa.float64(), nullable=False, metadata={}), 2), nullable=False, metadata={}, ), pa.field( "y_range", pa.list_(pa.field("item", pa.float64(), nullable=False, metadata={}), 2), nullable=False, metadata={}, ), ]) @staticmethod def _native_to_pa_array(data: Range2DArrayLike, data_type: pa.DataType) -> pa.Array: from rerun.encodings import Range1DBatch typed_data: Sequence[Range2D] if isinstance(data, Range2D): typed_data = [data] else: typed_data = data return pa.StructArray.from_arrays( [ Range1DBatch([x.x_range for x in typed_data]).as_arrow_array(), # type: ignore[misc, arg-type] Range1DBatch([x.y_range for x in typed_data]).as_arrow_array(), # type: ignore[misc, arg-type] ], fields=list(data_type), )