array
array
#
Array — a homogeneous sequence that broadcasts attribute access over its elements.
Array
#
Bases: CGType
A homogeneous sequence.
Array[T] is storable when T is (so Array[Path[V]] is a
non-storable view); a bare Array is the schemaless broadcast view a
projection lands in. The type parameter types the element surface
(indexing, iteration, append), and map/pmap carry the
function's return type. A broadcast or projection names a field no type
system can resolve, so it carries Any elements — the caller's next
call types them.
Source code in capturegraph-lib/capturegraph/types/containers/array.py
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 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 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 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 | |
dkeys
property
#
The union of field/key names across all present rows.
dtype
property
#
The type of the first present row (descends nested arrays), or None.
__add__(other)
#
__array__(dtype=None, copy=True)
#
NumPy's array-conversion protocol hook — see to_numpy.
Source code in capturegraph-lib/capturegraph/types/containers/array.py
__bool__()
#
__call__(*args, **kwargs)
#
Call each element with the same arguments (the elements are callables).
Raises if the call fails on every element for a non-data reason (every
element non-callable is a typo); a sparse failure chains as Missing.
Source code in capturegraph-lib/capturegraph/types/containers/array.py
__class_getitem__(element)
#
Build Array[element] — a storable subclass, or a typing-only alias.
A CGType element makes Array[T] whose storability follows the
element: Array[Image] is storable, while Array[Path[V]] is a
non-storable fan-out collection (an array of positions, never written to
disk). A non-CGType element is a typing-only alias, so loaded values can
be annotated without a schema.
Source code in capturegraph-lib/capturegraph/types/containers/array.py
__dir__()
#
Standard members plus the broadcastable element field names.
Surfaces photos.location in REPL/notebook autocomplete; the
broadcast itself stays dynamically typed.
Source code in capturegraph-lib/capturegraph/types/containers/array.py
__eq__(other)
#
Equal to another Array or a plain list with the same elements.
Source code in capturegraph-lib/capturegraph/types/containers/array.py
__getattr__(name)
#
Broadcast attribute access over the elements.
A name no element has raises (a typo), a name some lack chains as
Missing; this array's own machinery is not an element field
(broadcastable).
Source code in capturegraph-lib/capturegraph/types/containers/array.py
__getitem__(key)
#
Index by position (int/slice) or project by str/tuple.
numbers.Integral is accepted alongside plain int so a NumPy
index (np.argmax etc.) works like one — this Array converts to and
from NumPy for analysis. An out-of-range index chains as Missing
(typed as the element).
Source code in capturegraph-lib/capturegraph/types/containers/array.py
__init__(items=())
#
Wrap items (any iterable, copied into a plain list) as an Array.
__iter__()
#
__len__()
#
__or__(default)
#
Fill Missing/None leaves with default.
A parallel sequence fills element-wise; this recurses into nested Arrays.
Source code in capturegraph-lib/capturegraph/types/containers/array.py
__radd__(other)
#
__repr__()
#
__setattr__(name, value)
#
Broadcast attribute assignment over the elements.
An empty array adopts the length of value, creating a plain dict
per entry; a non-empty array assigns element-wise (a same-length
sequence), broadcasts a single-element sequence or a scalar, and skips
Missing elements. Each element is written by attribute when it
supports one, else by key (a dict row).
Source code in capturegraph-lib/capturegraph/types/containers/array.py
append(item)
#
load(base)
classmethod
#
The array stored at base, elements in index order; an unwritten tree is empty.
Raises:
| Type | Description |
|---|---|
TypeError
|
If this array is schemaless. |
Source code in capturegraph-lib/capturegraph/types/containers/array.py
map(function, label=None)
#
Apply function to each element, collecting failures as Missing.
The walk is a progress step counting the elements, shown as label
or function's name. Raises if the call fails on every element for a
non-data reason (a broken lambda fails loudly); a sparse data-absence
failure chains as Missing.
Source code in capturegraph-lib/capturegraph/types/containers/array.py
map_leaves(function)
#
Apply function to every leaf, descending into nested Arrays.
Raises if the call fails on every leaf for a non-data reason (a broken
lambda fails loudly); a sparse data-absence failure chains as Missing.
Source code in capturegraph-lib/capturegraph/types/containers/array.py
pmap(function, label=None)
#
Like map, across the process's one thread pool, sized to the CPU count.
Parallel only where function releases the GIL: decoding an image,
NumPy, a subprocess. cg.parallelism(workers) caps how many elements
are in flight at once. Each worker runs in a copy of the caller's
context, so the active scratch, workspace and progress step carry over;
a pmap inside a worker runs sequentially, the outer pool being the
parallelism.
Source code in capturegraph-lib/capturegraph/types/containers/array.py
schema()
classmethod
#
This array's wire form: its element's schema, tagged "array".
Source code in capturegraph-lib/capturegraph/types/containers/array.py
store(base, value)
classmethod
#
Write value under base, one zero-padded index entry per element.
Raises:
| Type | Description |
|---|---|
TypeError
|
If this array is schemaless, |
Source code in capturegraph-lib/capturegraph/types/containers/array.py
to_dict(keys=None)
#
Column-orient as {name: [values]} for a DataFrame.
With no keys, the union of leaf field names is used; Missing is
written as None.
Source code in capturegraph-lib/capturegraph/types/containers/array.py
to_numpy()
#
Convert to a NumPy array, mapping Missing/None to nan.
broadcast(items, operation, function)
#
function over items, isolated per element and guarded as a whole.
The one broadcast rule Array and Map share.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
Iterable[I]
|
The elements to apply |
required |
operation
|
str
|
Names this broadcast in the failure message. |
required |
function
|
Callable[[I], R]
|
The per-element operation. |
required |
Returns:
| Type | Description |
|---|---|
list[R]
|
One result per element, in order; a per-element failure is a reasoned |
list[R]
|
|
Raises:
| Type | Description |
|---|---|
Exception
|
The first element's reason, when every element failed for a non-data reason — see guard_broadcast. |
Source code in capturegraph-lib/capturegraph/types/containers/array.py
broadcastable(container, name)
#
Whether name is an element field to broadcast rather than the container's own machinery.
A dunder is Python's own protocol and a declared slot is the container's
storage: copy, pickle and notebook probes look those up and must see
a plain miss. Every other name broadcasts, a hidden schema field
(_metadata) included.
Source code in capturegraph-lib/capturegraph/types/containers/array.py
index_name(index)
#
The on-disk folder name for the array element at index.
Zero-padded to a fixed width so the ascending-lexicographic entry_stems
order (the cross-platform enumeration contract) matches numeric order.
Source code in capturegraph-lib/capturegraph/types/containers/array.py
isolated(function, item)
#
function(item) with per-element isolation: a failure becomes Missing.
The substitutions a broadcast makes — Missing for a failure, an
Array for a raw list — keep function's return type, the way a
Missing chains as the element it stands in for.
Source code in capturegraph-lib/capturegraph/types/containers/array.py
map_broadcast(items, function, label)
#
broadcast under a step counting the elements: the rule behind map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
Sequence[I]
|
The elements to apply |
required |
function
|
Callable[[I], R]
|
The per-element operation. |
required |
label
|
str | None
|
What the step shows; |
required |
Source code in capturegraph-lib/capturegraph/types/containers/array.py
parse_index_name(name)
#
The array index a folder name encodes, or raise if it is not one.
Canonical means exactly index_name(i): ASCII digits, zero-padded to the
fixed width (wider only for a huge index), no sign and no alias padding — so a
hostile path component cannot masquerade as an index it does not equal.