Skip to content

rpy2 converters

Type aliases for R↔Python conversion functions.

brmspy performs most conversion inside the worker process (where embedded R lives). Converters may optionally use shared memory (ShmPool) to avoid extra copies when moving large numeric data across the main↔worker boundary.

This module only defines type aliases used by converter registries and helper code under [brmspy.helpers._rpy2][].

Notes
  • The main process must not import rpy2.robjects. These aliases only refer to the lower-level rpy2.rinterface_lib.sexp.Sexp handle type.

Attributes

PyObject = Union[dict, list, str, float, int, np.dtype, None, Any, pd.DataFrame, pd.Series, np.ndarray, az.InferenceData, xr.DataArray, xr.Dataset] module-attribute

Union of common Python-side objects produced by R→Python conversion.

This is intentionally broad: brmspy frequently returns standard scientific Python types (NumPy/pandas/xarray/ArviZ), plus plain dict/list primitives.

Note

Avoid adding Any here unless absolutely necessary; it defeats the purpose of having this alias.

R2pyConverter = Callable[[Any, ShmPool | None], PyObject] module-attribute

Callable signature for an R→Python converter.

Parameters:

Name Type Description Default
obj Any

R-side object (usually an rpy2 wrapper type).

required
shm ShmPool or None

Shared memory pool used to allocate backing buffers for large numeric payloads.

required

Returns:

Type Description
PyObject

Py2rConverter = Callable[[Any], Sexp] module-attribute

Callable signature for a Python→R converter.

Parameters:

Name Type Description Default
obj Any

Python object to convert.

required

Returns:

Type Description
Sexp

Low-level R object handle.

Classes