Polars

https://www.pola.rs

Warning

This backend is experimental and is subject to backwards incompatible changes.

Install

Install Ibis and dependencies for the Polars backend:

Install with the polars extra:

pip install 'ibis-framework[polars]'

And connect:

import ibis

con = ibis.polars.connect()
1
Adjust connection parameters as needed.

Install for Polars:

conda install -c conda-forge ibis-polars

And connect:

import ibis

con = ibis.polars.connect()
1
Adjust connection parameters as needed.

Install for Polars:

mamba install -c conda-forge ibis-polars

And connect:

import ibis

con = ibis.polars.connect()
1
Adjust connection parameters as needed.

Connect

ibis.polars.connect

con = ibis.polars.connect()
Note

ibis.polars.connect is a thin wrapper around ibis.backends.polars.Backend.do_connect.

Connection Parameters

do_connect

do_connect(self, tables=None)

Construct a client from a dictionary of polars LazyFrames and/or DataFrames.

Parameters
Name Type Description Default
tables MutableMapping[str, pl.LazyFrame | pl.DataFrame] | None An optional mapping of string table names to polars LazyFrames. None

polars.Backend

compile

compile(self, expr, params=None, **_)

Compile an expression.

create_table

create_table(self, name, obj=None, *, schema=None, database=None, temp=None, overwrite=False)

Create a new table.

Parameters

Name Type Description Default
name str Name of the new table. required
obj pd.DataFrame | pa.Table | ir.Table | None An Ibis table expression or pandas table that will be used to extract the schema and the data of the new table. If not provided, schema must be given. None
schema ibis.Schema | None The schema for the new table. Only one of schema or obj can be provided. None
database str | None Name of the database where the table will be created, if not the default. None
temp bool Whether a table is temporary or not False
overwrite bool Whether to clobber existing data False

Returns

Type Description
Table The table that was created.

create_view

create_view(self, *_, **__)

Create a new view from an expression.

Parameters

Name Type Description Default
name str Name of the new view. required
obj ir.Table An Ibis table expression that will be used to create the view. required
database str | None Name of the database where the view will be created, if not provided the database’s default is used. None
overwrite bool Whether to clobber an existing view with the same name False

Returns

Type Description
Table The view that was created.

database

database(self, name=None)

Return a Database object for the name database.

Parameters

Name Type Description Default
name str | None Name of the database to return the object for. None

Returns

Type Description
Database A database object for the specified database.

drop_table

drop_table(self, *_, **__)

Drop a table.

Parameters

Name Type Description Default
name str Name of the table to drop. required
database str | None Name of the database where the table exists, if not the default. None
force bool If False, an exception is raised if the table does not exist. False

drop_view

drop_view(self, *_, **__)

Drop a view.

Parameters

Name Type Description Default
name str Name of the view to drop. required
database str | None Name of the database where the view exists, if not the default. None
force bool If False, an exception is raised if the view does not exist. False

execute

execute(self, expr, params=None, limit=None, **kwargs)

Execute an expression.

get_schema

get_schema(self, table_name, database=None)

has_operation

has_operation(cls, operation)

Return whether the backend implements support for operation.

Parameters

Name Type Description Default
operation type[ops.Value] A class corresponding to an operation. required

Returns

Type Description
bool Whether the backend implements the operation.

Examples

>>> import ibis
>>> import ibis.expr.operations as ops
>>> ibis.sqlite.has_operation(ops.ArrayIndex)
False
>>> ibis.postgres.has_operation(ops.ArrayIndex)
True

list_tables

list_tables(self, like=None, database=None)

Return the list of table names in the current database.

For some backends, the tables may be files in a directory, or other equivalent entities in a SQL database.

Parameters

Name Type Description Default
like str | None A pattern in Python’s regex format. None
database str | None The database from which to list tables. If not provided, the current database is used. None

Returns

Type Description
list[str] The list of the table names that match the pattern like.

read_csv

read_csv(self, path, table_name=None, **kwargs)

Register a CSV file as a table.

Parameters

Name Type Description Default
path str | Path The data source. A string or Path to the CSV file. required
table_name str | None An optional name to use for the created table. This defaults to a sequentially generated name. None
**kwargs Any Additional keyword arguments passed to Polars loading function. See https://pola-rs.github.io/polars/py-polars/html/reference/api/polars.scan_csv.html for more information. {}

Returns

Type Description
ir.Table The just-registered table

read_delta

read_delta(self, path, table_name=None, **kwargs)

Register a Delta Lake as a table in the current database.

Parameters

Name Type Description Default
path str | Path The data source(s). Path to a Delta Lake table directory. required
table_name str | None An optional name to use for the created table. This defaults to a sequentially generated name. None
**kwargs Any Additional keyword arguments passed to Polars loading function. See https://pola-rs.github.io/polars/py-polars/html/reference/api/polars.scan_delta.html for more information. {}

Returns

Type Description
ir.Table The just-registered table

read_json

read_json(self, path, table_name=None, **kwargs)

Register a JSON file as a table.

Parameters

Name Type Description Default
path str | Path A string or Path to a JSON file; globs are supported required
table_name str | None An optional name to use for the created table. This defaults to a sequentially generated name. None
**kwargs Any Additional keyword arguments passed to Polars loading function. See https://pola-rs.github.io/polars/py-polars/html/reference/api/polars.scan_ndjson.html for more information. {}

Returns

Type Description
ir.Table The just-registered table

read_pandas

read_pandas(self, source, table_name=None, **kwargs)

Register a Pandas DataFrame or pyarrow Table a table in the current database.

Parameters

Name Type Description Default
source pd.DataFrame The data source. required
table_name str | None An optional name to use for the created table. This defaults to a sequentially generated name. None
**kwargs Any Additional keyword arguments passed to Polars loading function. See https://pola-rs.github.io/polars/py-polars/html/reference/api/polars.from_pandas.html for more information. {}

Returns

Type Description
ir.Table The just-registered table

read_parquet

read_parquet(self, path, table_name=None, **kwargs)

Register a parquet file as a table in the current database.

Parameters

Name Type Description Default
path str | Path | Iterable[str] The data source(s). May be a path to a file, an iterable of files, or directory of parquet files. required
table_name str | None An optional name to use for the created table. This defaults to a sequentially generated name. None
**kwargs Any Additional keyword arguments passed to Polars loading function. See https://pola-rs.github.io/polars/py-polars/html/reference/api/polars.scan_parquet.html for more information (if loading a single file or glob; when loading multiple files polars’ scan_pyarrow_dataset method is used instead). {}

Returns

Type Description
ir.Table The just-registered table

register

register(self, source, table_name=None, **kwargs)

Register a data source as a table in the current database.

Parameters

Name Type Description Default
source str | Path | Any The data source(s). May be a path to a file, a parquet directory, or a pandas dataframe. required
table_name str | None An optional name to use for the created table. This defaults to a sequentially generated name. None
**kwargs Any Additional keyword arguments passed to Polars loading functions for CSV or parquet. See https://pola-rs.github.io/polars/py-polars/html/reference/api/polars.scan_csv.html and https://pola-rs.github.io/polars/py-polars/html/reference/api/polars.scan_parquet.html for more information {}

Returns

Type Description
ir.Table The just-registered table

sql

sql(self, query, schema=None, dialect=None)

table

table(self, name, _schema=None)

Construct a table expression.

Parameters

Name Type Description Default
name str Table name required
database str | None Database name None

Returns

Type Description
Table Table expression

to_pyarrow

to_pyarrow(self, expr, params=None, limit=None, **kwargs)

Execute expression and return results in as a pyarrow table.

This method is eager and will execute the associated expression immediately.

Parameters

Name Type Description Default
expr ir.Expr Ibis expression to export to pyarrow required
params Mapping[ir.Scalar, Any] | None Mapping of scalar parameter expressions to value. None
limit int | str | None An integer to effect a specific row limit. A value of None means “no limit”. The default is in ibis/config.py. None
kwargs Any Keyword arguments {}

Returns

Type Description
Table A pyarrow table holding the results of the executed expression.

to_pyarrow_batches

to_pyarrow_batches(self, expr, *, params=None, limit=None, chunk_size=1000000, **kwargs)

Execute expression and return a RecordBatchReader.

This method is eager and will execute the associated expression immediately.

Parameters

Name Type Description Default
expr ir.Expr Ibis expression to export to pyarrow required
limit int | str | None An integer to effect a specific row limit. A value of None means “no limit”. The default is in ibis/config.py. None
params Mapping[ir.Scalar, Any] | None Mapping of scalar parameter expressions to value. None
chunk_size int Maximum number of rows in each returned record batch. 1000000
kwargs Any Keyword arguments {}

Returns

Type Description
results RecordBatchReader
Back to top