_arrays
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.
Classes¶
ShmPool
¶
Minimal interface for allocating and attaching shared-memory blocks.
The concrete implementation lives in
brmspy._session.transport.ShmPool and tracks
blocks so they can be closed on teardown.
Source code in brmspy/types/shm.py
Functions¶
__init__(manager)
¶
Create a pool bound to an existing SharedMemoryManager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manager
|
SharedMemoryManager
|
Manager used to allocate blocks. |
required |
Source code in brmspy/types/shm.py
alloc(size, temporary=False)
¶
Allocate a new shared-memory block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Size in bytes. |
required |
Returns:
| Type | Description |
|---|---|
ShmBlock
|
Newly allocated block. |
Source code in brmspy/types/shm.py
attach(ref)
¶
Attach to an existing shared-memory block by name.
Returns:
| Type | Description |
|---|---|
ShmBlock
|
Attached block. |
close_all()
¶
ShmArray
¶
Bases: ndarray
NumPy array view backed by a shared-memory block.
Attributes:
| Name | Type | Description |
|---|---|---|
block |
ShmRef
|
Reference to the shared-memory block backing the array data. |
Notes
This is a view over SharedMemory.buf. Closing/unlinking the underlying
shared memory while the array is still in use will lead to undefined
behavior.
Source code in brmspy/types/shm_extensions.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
Attributes¶
_shm_metadata
instance-attribute
¶
Functions¶
from_metadata(meta, block)
classmethod
¶
Source code in brmspy/types/shm_extensions.py
from_block(block, shape, dtype, **kwargs)
classmethod
¶
Create an array view backed by an existing shared-memory block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block
|
ShmBlock
|
Attached shared-memory block. |
required |
shape
|
tuple[int, ...]
|
Desired array shape. |
required |
dtype
|
dtype
|
NumPy dtype of the array. |
required |
**kwargs
|
Reserved for future compatibility. Currently unused. |
{}
|
Returns:
| Type | Description |
|---|---|
ShmArray
|
Array view into the shared-memory buffer. |
Source code in brmspy/types/shm_extensions.py
array_order(a)
classmethod
¶
Determine how an array can be reconstructed from a raw buffer.
Returns "C" for C-contiguous arrays, "F" for Fortran-contiguous arrays,
otherwise "non-contiguous" (meaning: bytes were obtained by forcing
a contiguous copy during encoding).
Source code in brmspy/types/shm_extensions.py
is_string_object(a, sample=1000)
classmethod
¶
Source code in brmspy/types/shm_extensions.py
to_shm(obj, shm_pool)
classmethod
¶
Source code in brmspy/types/shm_extensions.py
ShmDataFrameColumns
¶
Bases: DataFrame
pandas DataFrame backed by per-column shared-memory blocks (numeric only).
Attributes:
| Name | Type | Description |
|---|---|---|
_blocks_columns |
dict[str, PandasColumnMetadata]
|
Mapping from column name to data required for its reconstruction |
Source code in brmspy/types/shm_extensions.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | |
Attributes¶
_metadata = ['_shm_metadata']
class-attribute
instance-attribute
¶
_shm_metadata
instance-attribute
¶
_constructor
property
¶
Functions¶
_create_col_metadata(series, block, arr=None, **params)
classmethod
¶
Source code in brmspy/types/shm_extensions.py
_set_col_raw(col, value)
¶
_set_shm_metadata(meta)
¶
_put_col_in_shm(df, col, shm_pool, replace=False)
classmethod
¶
Source code in brmspy/types/shm_extensions.py
_reconstruct_series(meta, block, nrows, index)
classmethod
¶
Source code in brmspy/types/shm_extensions.py
__setitem__(key, value)
¶
_on_column_added(col)
¶
ShmDataFrameSimple
¶
Bases: DataFrame
pandas DataFrame backed by a single shared-memory block (numeric only).
Attributes:
| Name | Type | Description |
|---|---|---|
block |
ShmRef
|
Reference to the shared-memory block backing the DataFrame's values. |
Source code in brmspy/types/shm_extensions.py
Attributes¶
_metadata = ['_shm_metadata']
class-attribute
instance-attribute
¶
_shm_metadata
instance-attribute
¶
Functions¶
from_block(block, nrows, ncols, columns, index, dtype)
classmethod
¶
Construct a DataFrame backed by a single SHM block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block
|
ShmBlock
|
Attached shared-memory block containing a contiguous 2D numeric matrix. |
required |
nrows
|
int
|
DataFrame shape. |
required |
ncols
|
int
|
DataFrame shape. |
required |
columns
|
list[Any] or None
|
Column/index labels. |
required |
index
|
list[Any] or None
|
Column/index labels. |
required |
dtype
|
str or dtype
|
Dtype of the matrix stored in the block. |
required |
Returns:
| Type | Description |
|---|---|
ShmDataFrameSimple
|
|
Source code in brmspy/types/shm_extensions.py
Functions¶
_get_rvector_memview(obj)
¶
Source code in brmspy/helpers/_rpy2/_converters/_vectors.py
_get_rvector_types(obj)
¶
Source code in brmspy/helpers/_rpy2/_converters/_vectors.py
_r2py_vector(obj, shm=None, allow_scalar=True)
¶
Source code in brmspy/helpers/_rpy2/_converters/_vectors.py
log_warning(msg, method_name=None)
¶
Log a warning message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg
|
str
|
The warning message to log |
required |
method_name
|
str
|
The name of the method/function. If None, will auto-detect from call stack. |
None
|
Source code in brmspy/helpers/log.py
_rmatrix_info(obj)
¶
Source code in brmspy/helpers/_rpy2/_converters/_arrays.py
_rmatrix_to_py_default(obj)
¶
Source code in brmspy/helpers/_rpy2/_converters/_arrays.py
_rmatrix_to_py(obj, shm=None)
¶
Source code in brmspy/helpers/_rpy2/_converters/_arrays.py
_r2py_matrix(obj, shm=None)
¶
_r2py_dataframe_fallback(obj)
¶
Fallback conversion for R data.frame -> pandas.DataFrame.
Notes
In some environments, rpy2/pandas2ri may convert R factors to their underlying
integer codes instead of pandas.Categorical. Since brmspy relies on factors
roundtripping as categoricals (and we have custom factor handling in
_r2py_vector()),
we patch factor columns explicitly here.