TableVStack

class lsst.obs.base.TableVStack(capacity: int)

Bases: object

A helper class for stacking astropy tables without having them all in memory at once.

Parameters:
capacityint

Full size of the final table.

Notes

Unlike astropy.table.vstack, this class requires all tables to have the exact same columns (it’s slightly more strict than even the join_type="exact" argument to astropy.table.vstack).

Methods Summary

extend(table[, extra_values])

Add a single table to the stack.

from_handles(handles)

Construct from an iterable of

set_extra_values(table, key, values, capacity)

Set extra column values in a slice of a table.

vstack_handles(handles[, extra_values, ...])

Vertically stack tables represented by deferred dataset handles.

Methods Documentation

extend(table: Table, extra_values: dict[str, Union[collections.abc.Buffer, numpy._typing._array_like._SupportsArray[numpy.dtype[Any]], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype[Any]]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[bool | int | float | complex | str | bytes]]] | None = None) None

Add a single table to the stack.

Parameters:
tableastropy.table.Table

An astropy table instance.

extra_valuesdict

Dict keyed by column name with an array-like of values to set for this table only.

classmethod from_handles(handles: Iterable[DeferredDatasetHandle]) Self
Construct from an iterable of

lsst.daf.butler.DeferredDatasetHandle.

Parameters:
handlesIterable [ lsst.daf.butler.DeferredDatasetHandle ]

Iterable of handles. Must have a storage class that supports the “rowcount” component, which is all that will be fetched.

Returns:
vstackTableVStack

An instance of this class, initialized with capacity equal to the sum of the rowcounts of all the given table handles.

classmethod set_extra_values(table: Table, key: str, values: Any, capacity: int, slicer: slice | None = None, validate: bool = True) None

Set extra column values in a slice of a table.

Parameters:
tableastropy.table.Table

The table to set values for.

keystr

The column key.

valuesAny

The value(s) to set. Can be a scalar.

capacityint

The size to initialize the column with, if it doesn’t exist yet.

slicerslice or None, optional

A slice to select values to update.

validatebool, optional

If True and the column already exists, will raise if the new values do not match the existing ones.

classmethod vstack_handles(handles: Iterable[DeferredDatasetHandle], extra_values: dict[int, dict[str, Union[collections.abc.Buffer, numpy._typing._array_like._SupportsArray[numpy.dtype[Any]], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype[Any]]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[bool | int | float | complex | str | bytes]]]] | None = None, kwargs_get: dict[str, Any] | None = None) Table

Vertically stack tables represented by deferred dataset handles.

Parameters:
handlesIterable [ lsst.daf.butler.DeferredDatasetHandle ]

Iterable of handles. Must have the “ArrowAstropy” storage class and identical columns.

extra_valuesdict

Dictionary keyed by index of handle of additional values to pass to extend.

kwargs_getdict`[`str, Any]

Keyword argument-value pairs to pass to handle.get().

Returns:
tableastropy.table.Table

Concatenated table with the same columns as each input table and the rows of all of them, or an empty table if there are no handles.