String-powered Polars expression engine with extended DataFrame utilities
Project description
Polynx
String-powered Polars expression engine with extended DataFrame utilities.
Table of Contents
Installation
Via PyPI (Recommended)
Install using pip:
pip install polynx
From Souce
Clone the repository and install using pip:
git clone https://github.com/LowellWinston/polynx.git
cd polynx
pip install .
Usage
import polynx as plx
- Supports all polars functions
df = plx.DataFrame({
'A':[1, 2, 3, 4],
'B': ['abc', 'bc', 'aaa', None],
'C': ['2023-01-01','2021-01-01','2009-11-01','2000-11-11'],
'E': [1.1, 2.1, 3.5, 0]}
).wc("C.str.to_datetime(format='%Y-%m-%d',time_unit='ns').dt.date()")
df
| A | B | C | E |
|---|---|---|---|
| i64 | str | date | f64 |
| 1 | "abc" | 2023-01-01 | 1.1 |
| 2 | "bc" | 2021-01-01 | 2.1 |
| 3 | "aaa" | 2009-11-01 | 3.5 |
| 4 | null | 2000-11-11 | 0.0 |
- Pandas style query function with chaind comparison, variable substituion in string expression
var1 = 1
var2 = 3
var3 = ['bc']
query_str = "@var1 <= A < @var2 & C.dt.year() >=2020 & B in @var3"
df.query(query_str)
| A | B | C | E |
|---|---|---|---|
| i64 | str | date | f64 |
| 2 | "bc" | 2021-01-01 | 2.1 |
- String operation
query_str = "B.str.contains('a|b')"
#query_str = " B.str.ends_with('c')"
df.query(query_str)
| A | B | C | E |
|---|---|---|---|
| i64 | str | date | f64 |
| 1 | "abc" | 2023-01-01 | 1.1 |
| 2 | "bc" | 2021-01-01 | 2.1 |
| 3 | "aaa" | 2009-11-01 | 3.5 |
- Year month comparison in string format
var5 ='2001-01-01'
var3 = '2020-01-01'
query_str = " @var5 < C < @var3 "
df.query(query_str)
| A | B | C | E |
|---|---|---|---|
| i64 | str | date | f64 |
| 2 | "bc" | 2021-01-01 | 2.1 |
inandnot in
query_str = " B in ['aaa','bc']"
df.query(query_str)
| A | B | C | E |
|---|---|---|---|
| i64 | str | date | f64 |
| 2 | "bc" | 2021-01-01 | 2.1 |
| 3 | "aaa" | 2009-11-01 | 3.5 |
- Math calcuation
query_str = " A ** 2 - E > 1"
df.query(query_str)
| A | B | C | E |
|---|---|---|---|
| i64 | str | date | f64 |
| 2 | "bc" | 2021-01-01 | 2.1 |
| 3 | "aaa" | 2009-11-01 | 3.5 |
| 4 | null | 2000-11-11 | 0.0 |
- Pandas style eval function
query_str = " (A ** 2 - E)/(10-A)"
df.eval(query_str)
| A |
|---|
| f64 |
| -0.011111 |
| 0.2375 |
| 0.785714 |
| 2.666667 |
- negation
query_str = " not (B.is_null() & A.is_not_null())"
df.query(query_str)
| A | B | C | E |
|---|---|---|---|
| i64 | str | date | f64 |
| 1 | "abc" | 2023-01-01 | 1.1 |
| 2 | "bc" | 2021-01-01 | 2.1 |
| 3 | "aaa" | 2009-11-01 | 3.5 |
- wc extends with_columns to support multipe statement assignments
df.wc("A.sum().over('B').alias('H'); E.mean().alias('E_mean')")
| A | B | C | E | H | E_mean |
|---|---|---|---|---|---|
| i64 | str | date | f64 | i64 | f64 |
| 1 | "abc" | 2023-01-01 | 1.1 | 1 | 1.675 |
| 2 | "bc" | 2021-01-01 | 2.1 | 2 | 1.675 |
| 3 | "aaa" | 2009-11-01 | 3.5 | 3 | 1.675 |
| 4 | null | 2000-11-11 | 0.0 | 4 | 1.675 |
- Extend describe for group by
df.describe(group_keys='B', selected_columns=['A','E']).round()
- Extend group_by to work with string expressions
df.gb('B', " A.sum(); E.mean()")
| B | A | E |
|---|---|---|
| str | f64 | f64 |
| null | 4.0 | 0.0 |
| "aaa" | 3.0 | 3.5 |
| "abc" | 1.0 | 1.1 |
| "bc" | 2.0 | 2.1 |
- Support lazyframe
df.lazy().wc("E = 1").collect()
| A | B | C | E |
|---|---|---|---|
| i64 | str | date | i32 |
| 1 | "abc" | 2023-01-01 | 1 |
| 2 | "bc" | 2021-01-01 | 1 |
| 3 | "aaa" | 2009-11-01 | 1 |
| 4 | null | 2000-11-11 | 1 |
Features
- String-powered expression engine for Polars DataFrames
- Support for complex mathematical and statistical operations
- Easy-to-use syntax for powerful data manipulation
- Fast and scalable, optimized for large datasets
Documentation
TO BE UPDATED.
Contributing
We welcome contributions! If you'd like to help improve this project, please fork the repository, make your changes, and submit a pull request.
LICENSES
This project is licensed under the MIT License - see the LICENSE file for details.
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 polynx-0.1.7.tar.gz.
File metadata
- Download URL: polynx-0.1.7.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff610a5cd973047a18df299a2258735ec4339e994df654378878842fe29ba400
|
|
| MD5 |
075457e8e884737f4042833a4d46a6a7
|
|
| BLAKE2b-256 |
9abf49f2096adc3b674b956259f92dee5af91343101ec7ba40d3c3fa47186d17
|
File details
Details for the file polynx-0.1.7-py3-none-any.whl.
File metadata
- Download URL: polynx-0.1.7-py3-none-any.whl
- Upload date:
- Size: 15.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44a8db636c4c1fd1d81da30ac396abd10a3b59b37d756bb86a40f31fca5b058d
|
|
| MD5 |
4e8cb1bacc8c4f1526cd987ee1fc55f2
|
|
| BLAKE2b-256 |
b9bd15e14940e378a3dc3f00e762cf26b1ea969699517f671ebbb616326ea06e
|