memtable

xorq.memtable(data, *, columns=None, schema=None, name=None)

Construct an ibis table expression from in-memory data.

Parameters

Name Type Description Default
data A table-like object (pandas.DataFrame, pyarrow.Table, or polars.DataFrame), or any data accepted by the pandas.DataFrame constructor (e.g. a list of dicts). Note that ibis objects (e.g. MapValue) may not be passed in as part of data and will result in an error. Do not depend on the underlying storage type (e.g., pyarrow.Table), it’s subject to change across non-major releases. required
columns Iterable[str] | None Optional of column names. If provided, must match the number of columns in data. None
schema SchemaLike | None Optional Schema. The functions use data to infer a schema if not passed. None
name str | None Optional name of the table. None

Returns

Name Type Description
Table A table expression backed by in-memory data.

Examples

>>> import xorq as xo
>>> xo.options.interactive = False
>>> t = xo.memtable([{"a": 1}, {"a": 2}])
>>> t
InMemoryTable
  data:
    PandasDataFrameProxy:
         a
      0  1
      1  2
>>> t = xo.memtable([{"a": 1, "b": "foo"}, {"a": 2, "b": "baz"}])
>>> t
┏━━━━━━━┳━━━━━━━━┓
┃ a      b      ┃
┡━━━━━━━╇━━━━━━━━┩
│ int64string │
├───────┼────────┤
│     1foo    │
│     2baz    │
└───────┴────────┘

Create a table literal without column names embedded in the data and pass columns

>>> t = xo.memtable([(1, "foo"), (2, "baz")], columns=["a", "b"])
>>> t
┏━━━━━━━┳━━━━━━━━┓
┃ a      b      ┃
┡━━━━━━━╇━━━━━━━━┩
│ int64string │
├───────┼────────┤
│     1foo    │
│     2baz    │
└───────┴────────┘

Create a table literal without column names embedded in the data. Ibis generates column names if none are provided.

>>> t = xo.memtable([(1, "foo"), (2, "baz")])
>>> t
┏━━━━━━━┳━━━━━━━━┓
┃ col0   col1   ┃
┡━━━━━━━╇━━━━━━━━┩
│ int64string │
├───────┼────────┤
│     1foo    │
│     2baz    │
└───────┴────────┘