Skip to main content

polars-to-ibis

pypi

Convert Polars LazyFrames to Ibis unbound tables

Polars and Ibis have similar APIs, but while Polars supports computation in-memory and on Polars Cloud, Ibis by itself does not handle computation: Instead it translates the dataframe expression into idiomatic SQL for a particular database.

Example

First, we'll write to the database so we have something to query. To connect to a particular database, you will need to install the appropriate extra. Taking SQLite as an example:

$ pip install 'polars-to-ibis'
$ pip install 'ibis-framework[sqlite]'

Create the table for our example:

>>> import ibis
>>> import polars as pl
>>> connection = ibis.sqlite.connect()
>>> table_name = 'readme_example'
>>> connection.create_table(
...      table_name,
...      pl.DataFrame({"ints": [1, 2, 3, 4]}),
...      overwrite=True,
... )
DatabaseTable: readme_example
  ints int64

Now we can demonstrate the typical use of polars-to-ibis. To read a database table's schema and create a LazyFrame, use scan_database:

>>> from polars_to_ibis import scan_database, convert_polars_to_ibis
>>> polars_lazy = scan_database(connection, table_name)

Next, make a query starting with that LazyFrame:

>>> polars_query = polars_lazy.sum()
>>> ibis_unbound_table = convert_polars_to_ibis(
...     polars_query,
...     table_name=table_name,
... )
>>> print(ibis_unbound_table.to_sql())
SELECT
  SUM("t0"."ints") AS "ints"
FROM "readme_example" AS "t0"

Finally, we can execute in SQLite the query which we constructed in Polars and translated to Ibis:

>>> connection.to_polars(ibis_unbound_table).to_dict(as_series=False)
{'ints': [10]}

Limitations

  • Python versions: Tested against Python 3.10 and 3.13.
  • Polars versions: Tested against Polars 1.32.0, 1.36.1, and 1.41.2.
  • Ibis version: Tested against Ibis 11.0.0.
  • Feature coverage, and database quirks: We only cover a fraction of the Polars API, and even within that range there are often quirks in how a query is handled by a given database. The best summary is the collection of test scenarios.

Contributions

There are several ways to contribute. First, if you find polars_to_ibis useful, please let us know and we'll spend more time on this project. If polars_to_ibis doesn't work for you, we also want to know that! Please file an issue.

PRs that expand feature coverage are welcome. Please add a new scenarios to exercise new features, and run tests locally before submitting your PR.

If you have an idea that goes beyond just expanding coverage, please file an issue before beginning work, so we can make sure that your idea aligns with our roadmap.

Development

Getting Started

$ git clone https://github.com/opendp/polars-to-ibis.git
$ cd polars-to-ibis
$ pip install uv
$ uv sync
$ uv run pre-commit install

Testing

In-memory databases are handled by python and pip, but other databases covered by the tests will require installation and startup. (If you don't want to install extra database engines right now, they can be skipped during test runs: uv run pytest -k 'not extra_install')

On MacOS we recommend:

$ uv run scripts/setup.sh

At this point, tests should pass, and code coverage should be complete (except blocks we explicitly ignore):

$ uv run scripts/ci.sh

Release

  • Make one last feature branch with the new version number in the name:
    • Run uv run scripts/changelog.py to update the CHANGELOG.md.
    • Review the updates and pull a couple highlights to the top.
    • uv version --bump minor, and add the new number at the top of the CHANGELOG.md.
    • Commit your changes, make a PR, and merge this branch to main.
  • Update main with the latest changes: git checkout main; git pull
  • With ~/.pypirc in place, run uvx uv-publish.

Conventions

Branch names should be of the form NNNN-short-description, where NNNN is the issue number being addressed.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polars_to_ibis-0.2.0.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

polars_to_ibis-0.2.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file polars_to_ibis-0.2.0.tar.gz.

File metadata

  • Download URL: polars_to_ibis-0.2.0.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for polars_to_ibis-0.2.0.tar.gz
Algorithm Hash digest
SHA256 eb2ec3e4e95fd962ac6b58244f2679811f3c70c4afde9ae5443c1c57b897c3ed
MD5 7d709abdc9aad2c9107b72327e856520
BLAKE2b-256 f49bfea3c6183df26613ababe7daa67f4fe46559de20c35582a7a8a92b6eba3f

See more details on using hashes here.

File details

Details for the file polars_to_ibis-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: polars_to_ibis-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for polars_to_ibis-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6fa624039c4db49f875be59dcce3d3a6ee68e2007cbe1feba712f4e84f78a669
MD5 a97ee5e36f8e977a122428285a2264e0
BLAKE2b-256 71e3a9bf8f773f5242bfcdcd8aa58a4d819b8fc604f7f196a5b41a30b2af6704

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page