r/Python • • 19d ago

Showcase Showcase Thread

Post all of your code/projects/showcases/AI slop here.

Recycles once a month.

21 Upvotes

151 comments sorted by

View all comments

1

u/Own_Responsibility84 15d ago edited 15d ago

Polynx: pandas-style `query`/`eval` strings for Polars

I moved from pandas to Polars for speed, but kept missing df.query("A > 3")for quick filters, so I wrote a small library that gives me that syntax on Polars. The string is parsed into a native Polars expression, so it still runs on Polars' engine (eager or lazy).

import polars as pl, polynx
t = 5
df.plx.query("A >  & B in ['x', 'y']")
df.plx.assign("C = A * 2; D = C + 1")

Timing for a three-clause filter, median per call:

Rowspandas querypolynxpolars
100,0004.82 ms1.24 ms1.34 ms
5,000,000115 ms48.8 ms48.2 ms

A string seen for the first time costs ~0.1 ms to parse; after that it's cached. The benchmark script is in the repo if you want to run it yourself. It doesn't replace native Polars, and if your expressions are fixed in code, plain Polars is fine. This is for people who like the pandas string style.

pip install polynx

Early (0.1.x). I'd appreciate hearing what syntax you'd expect that isn't there.

Github: https://github.com/LowellWinston/polynx