Generic Parquet filtering tool (CLI + API)
Project description
pqfilt
Generic Parquet filtering tool (CLI and Python API).
- Originally developed while dealing with large Parquet files in SPHEREx mission (GitHub).
Main Purpose
pqfilt wraps pyarrow.dataset to let you filter Parquet files before they
are fully read into memory, using row-group-level filtering. This is very efficient/fast.
- Using
pqfilt.read()with filters will be orders of magnitude faster thanpd.read_parquet()for large datasets.- 240× faster on the SPHEREx's SSO ephemeris database (111 files, 139M rows; a 10-day
jd_tdbwindow skips 107 of 111 files entirely, 64 ms vs 15 s); - 1.8–2.3× faster on a 3.6M-row SPHEREx source catalog (single row group, compound filter, all/4 columns); gains are larger when the file has many files/row groups or sits on disk.
- 240× faster on the SPHEREx's SSO ephemeris database (111 files, 139M rows; a 10-day
- The syntax is designed to be intuitive and flexible
- e.g., "a > 5 & ~(b in 1,2) & v is not null" is much simpler than the equivalent
pyarrowexpression syntax or chaining multiple DataFrame filters together.
- e.g., "a > 5 & ~(b in 1,2) & v is not null" is much simpler than the equivalent
- Even if you already loaded a DataFrame, you can use
pqfilt.filter_df(df, 'a > 5 & ~(b in 1,2) & v is not null')to apply the same filter syntax to it.
Installation
pip install pqfilt
# or
uv add pqfilt
Python API
import pqfilt
# Simple filter
df = pqfilt.read("data.parquet", filters="vmag < 20")
# AND + OR with expression syntax
df = pqfilt.read("data.parquet", filters="(a < 30 & b > 50) | c == 1")
# Negation with ~ prefix
df = pqfilt.read("data.parquet", filters="~(a > 5)")
df = pqfilt.read("data.parquet", filters="a > 5 & ~(b in 1,2,'1','2')")
# Null checks
df = pqfilt.read("data.parquet", filters="v is null")
df = pqfilt.read("data.parquet", filters="v is not null")
# Boolean columns
df = pqfilt.read("data.parquet", filters="is_comet == True")
df = pqfilt.read("data.parquet", filters="is_comet != false")
# Membership filter (explicit quotes preserve string types, e.g., to prevent Parquet type errors)
# Supported array formats: "val1, val2", "(val1, val2)", "[val1, val2]"
df = pqfilt.read("data.parquet", filters="desig in '1', '2', '3'")
df = pqfilt.read("data.parquet", filters="desig in ('1', '2', '3')")
df = pqfilt.read("data.parquet", filters="desig in ['1', '2', '3']")
# Tuple syntax (flat AND)
df = pqfilt.read("data.parquet", filters=[("a", "<", 30), ("b", ">", 50)])
# Tuple syntax with null checks
df = pqfilt.read("data.parquet", filters=[("v", "is null", None)])
# DNF syntax (OR of ANDs)
df = pqfilt.read("data.parquet", filters=[
[("a", "<", 30)],
[("b", ">", 50)],
])
# Column selection + output
df = pqfilt.read("data/*.parquet", columns=["a", "b"], output="out.parquet")
# Filter an already-loaded DataFrame (same syntax)
df = pd.read_csv("data.csv")
filtered = pqfilt.filter_df(df, "a > 5 & ~(b in 1,2) & v is not null")
CLI
# Basic filter
pqfilt data/*.parquet -f "vmag < 20" -o filtered.parquet
# AND + OR expression
pqfilt data/*.parquet -f "(a < 30 & b > 50) | c == 1" -o filtered.parquet
# Multiple -f flags (AND-ed together)
pqfilt data/*.parquet -f "vmag < 20" -f "dec > 30" -o filtered.parquet
# Column selection
pqfilt data/*.parquet -f "vmag < 20" --columns vmag,ra,dec -o filtered.parquet
# Membership filter (enclosing brackets [] or () are automatically stripped)
pqfilt data/*.parquet -f "desig in [1, 2, 3]" -o filtered.parquet
Column names with special characters
Columns containing operator characters can be backtick-quoted:
pqfilt.read("data.parquet", filters="`alpha*360` > 100")
License
MIT
Project details
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 pqfilt-0.2.2.tar.gz.
File metadata
- Download URL: pqfilt-0.2.2.tar.gz
- Upload date:
- Size: 96.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3edbe22af14362b6df6be5171d016197d844d438a3bd76d7f0a9764d38dd0d5b
|
|
| MD5 |
92cdb096f9b56a740d496fa32ac34eed
|
|
| BLAKE2b-256 |
9e3d76fb6a644453b69ee5478faca491dbaac14d3138c2a03bbafac25e1e47d2
|
Provenance
The following attestation bundles were made for pqfilt-0.2.2.tar.gz:
Publisher:
publish.yml on ysBach/pqfilt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pqfilt-0.2.2.tar.gz -
Subject digest:
3edbe22af14362b6df6be5171d016197d844d438a3bd76d7f0a9764d38dd0d5b - Sigstore transparency entry: 1868115929
- Sigstore integration time:
-
Permalink:
ysBach/pqfilt@f793515558e527fca8149e13ae3827dc3aba74a2 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/ysBach
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f793515558e527fca8149e13ae3827dc3aba74a2 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pqfilt-0.2.2-py3-none-any.whl.
File metadata
- Download URL: pqfilt-0.2.2-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eec2d216a97fe17e194a3eb2e361705cf5421a4681c3b7b694118ba9ad740530
|
|
| MD5 |
47ae53a9474cd160a959547c747a1e31
|
|
| BLAKE2b-256 |
3cc49794002ec20baf7199bf81cb6fb58f0fc0112c676f258ae593698c1b667d
|
Provenance
The following attestation bundles were made for pqfilt-0.2.2-py3-none-any.whl:
Publisher:
publish.yml on ysBach/pqfilt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pqfilt-0.2.2-py3-none-any.whl -
Subject digest:
eec2d216a97fe17e194a3eb2e361705cf5421a4681c3b7b694118ba9ad740530 - Sigstore transparency entry: 1868115977
- Sigstore integration time:
-
Permalink:
ysBach/pqfilt@f793515558e527fca8149e13ae3827dc3aba74a2 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/ysBach
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f793515558e527fca8149e13ae3827dc3aba74a2 -
Trigger Event:
release
-
Statement type: