You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 460030f
Browse filesBrowse the repository at this point in the historyBrowse files
docs: rewrite the pandas engine guide around the readable-UDF pitch
The guide opened with `add_one(col) -> col + 1`, which measures 0.53x on a
1M x 8 frame — i.e. it led with a case where `engine=blosc2.jit` is twice as
slow as a plain `apply`. The actual payoff only appeared in a benchmark block
at the bottom.
Restructure so the first screenful explains why and when the engine helps:
- Replace the running example with Yeo-Johnson (the power transform behind
sklearn's PowerTransformer). Its parameter is fitted per column, so applying
it across every column is the correct semantics rather than an artifact, and
it is multi-statement, which is what the readability argument rests on.
- Add a two-panel plot measuring the two conditions separately: speedup vs
row count (break-even between 100k and 1M rows) and vs the number of fused
operations (2.1x for one, 3.8x for five).
- Keep `col + 1` as an explicit counter-example under "when not to use it".
- Move the `axis=` discussion and Limitations to the end as reference material.
Add an honest comparison against `pd.eval`/numexpr, which a reader arriving
from pandas' Enhancing performance page will ask about: numexpr is somewhat
faster on in-memory frames (3.14x vs 2.13x), and the argument for the Blosc2
engine is that you write a Python function rather than a quoted string.
Blosc2's compressed/out-of-core strength does not apply on this path, since
pandas materialises each column as a NumPy array first.
Document three gotchas found while measuring:
- Plain `apply` passes a Series (`std()` defaults to ddof=1) while the engine
passes an ndarray (ddof=0), so identical source computes different numbers.
- `np.where` evaluates both arms, so each must be clamped to its own domain;
without this the Yeo-Johnson example raises a negative base to a fractional
power for ~159k of 1M elements and floods the run with NaN warnings.
- `np.sign` is unsupported on traced expressions.
Also say "evaluates" rather than "compiles": with the default `jit=None`,
plain expressions go to miniexpr's bytecode interpreter, not a JIT-compiled
kernel. The win here is fusion, not compilation.
bench/bench_pandas_engine.py gains the two sweeps, a numexpr reference series
and the plot, so every figure quoted in the guide is reproducible.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
0 commit comments