Convert Polars LazyFrames to Ibis unbound tables
Project description
polars-to-ibis
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.
The public interface of polars_to_ibis consists of exactly one function: convert_polars_to_ibis.
Example
>>> import polars as pl
>>> from polars_to_ibis import convert_polars_to_ibis
>>> polars_lazy = pl.LazyFrame(schema=pl.Schema({"ints": pl.Int32}))
>>> polars_query = polars_lazy.sum()
>>> table_name = 'readme_example'
>>> 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"
This is generic SQL: To connect to a particular database, you will need to install the appropriate extra. Taking SQLite as an example:
pip install 'ibis-framework[sqlite]'
Now we'll actually connect to the database, and create a very small table:
>>> import ibis
>>> connection = ibis.sqlite.connect()
>>> try: # Ensure a clean slate.
... connection.drop_table(table_name)
... except BaseException:
... pass
>>> connection.create_table(table_name, pl.DataFrame({"ints": [1, 2, 3, 4]}))
DatabaseTable: readme_example
ints int64
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.33.0, and 1.34.0.
- 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 fixtures.
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 fixtures 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file polars_to_ibis-0.1.0.tar.gz.
File metadata
- Download URL: polars_to_ibis-0.1.0.tar.gz
- Upload date:
- Size: 25.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a4ef1880aa77a963c704630e7c88c4b0b236153eb264312b61cbf47c33fdf11
|
|
| MD5 |
35bfcbdfdf29bdf38343627958f78352
|
|
| BLAKE2b-256 |
7a192b2327db048809e3af0aef3ba83f72130e5cd9de0579f3ad3018ee2bb0e9
|
File details
Details for the file polars_to_ibis-0.1.0-py2.py3-none-any.whl.
File metadata
- Download URL: polars_to_ibis-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a27047c778396da69633c54ae4e9e9e1c0207c7ec0392c1c5be938141b9c9723
|
|
| MD5 |
5dd2919520b360f2c6746845705409ac
|
|
| BLAKE2b-256 |
5c890111c2ecdf3707456efecab2bb7e976263de9c7d7503a838f9fcabbfd932
|