colstore.TableView

class colstore.TableView(store, row_part, column_names)[source]

Bases: _ColumnTable, _BaseView

View of multiple columns produced by any non-string indexing.

Materializes through array() (one column, by name), dict(), recarray(), or frame(). There is no no-argument array() – several columns generally have different dtypes and cannot be packed into a single homogeneous ndarray; read one column by name (view['col'] / view.array('col')) or use recarray() for all of them. Indexing by a name projects a column (view['col'] → a ColumnView) and by a list of names a sub-table (view[['a', 'b']], the same as select()); a row selector (view[:100], view[idx], view[mask]) narrows the rows, composed onto the view’s selection, and view[rows, cols] does both.

Parameters:
  • store (_ReaderBase)

  • row_part (Any)

  • column_names (list[str])

__getitem__(key)[source]

Narrow this table by columns or rows.

view['col'] / view[['a', 'b']] project columns (as before); a row selector – view[:100], view[idx], view[mask] – narrows the rows, composed onto the view’s current selection; and view[rows, cols] does both. So ds[:1000, cols][:10] equals ds[:10, cols].

Parameters:

key (Any)

Return type:

ColumnView | TableView

property columns: list[str]

Names of the columns selected by this view, in selection order.

property n_columns: int

Number of columns selected by this view.

select(*columns)[source]

Narrow this view to the named columns (in the given order), same rows.

Unknown names raise KeyError; a single name still yields a (one-column) TableView. The row selection – including a lazy col() / query predicate – is preserved.

Parameters:

columns (str)

Return type:

TableView

drop(*columns)[source]

Drop the named columns, keeping the rest in stored order and the same rows.

Parameters:

columns (str)

Return type:

TableView

property dtypes: dict[str, dtype]

Per-column NumPy dtypes.

dict(copy=True)[source]

Materialize as a dict mapping column name to 1D ndarray.

Parameters:

copy (bool, optional) – True (default): owning arrays. False: READ-ONLY zero-copy views backed by the store’s open memmaps, all-or-nothing – see ColumnView.array() for the exact support conditions and lifetime semantics. recarray has no zero-copy form (it repacks by construction); frame accepts copy and forwards it here, so frame(copy=False) aliases the same views.

Returns:

dict[str, numpy.ndarray] – Arrays in selection order; each column’s stored dtype is preserved.

Return type:

dict[str, ndarray]

recarray()[source]

Materialize as a structured (record) ndarray with one field per column.

Returns:

numpy.ndarray – Structured 1D array. result[name] returns the column.

Return type:

ndarray

frame(copy=True)[source]

Materialize as a pandas DataFrame.

Parameters:

copy (bool, optional) – True (default): owning columns. False: a READ-ONLY DataFrame whose columns are zero-copy views, forwarding the same conditions and lifetime as dict() (raising rather than copying when any column cannot be viewed).

Returns:

pandas.DataFrame – Columns are in selection order with their stored dtypes preserved.

Return type:

pd.DataFrame

evaluate()[source]

Resolve the (lazy) row selection now; return a view over the concrete rows.

For a col() / query selection this reads the predicate columns and computes the boolean row mask once, returning an equivalent view whose rows are already resolved – so a later .frame() / .dict() / .recarray() (or the head/preview helpers) does not recompute the selection. The selected columns are not materialized.

Return type:

TableView

head(n=None)[source]

First n rows of the selection as a previewable peek (default config rows).

Parameters:

n (int | None)

Return type:

Preview

tail(n=None)[source]

Last n rows of the selection, as a previewable peek.

Parameters:

n (int | None)

Return type:

Preview