Skip to content

fix(orderbook): use pl.len() for trade counts (polars 2.0 compat, refs #162) - #168

Merged
TexasCoding merged 1 commit into
mainfrom
maint/162-polars2-pl-len
Oct 15, 2026
Merged

TexasCoding merged 1 commit into
mainfrom
maint/162-polars2-pl-len

Conversation

@TexasCoding

Copy link
Copy Markdown
Owner

Unblocks Dependabot #162 (polars 1.44.2 -> 2.0.0).

pyproject.toml allows polars>=1.31.0 with no upper bound, so fresh installs already resolve polars 2.0. Under polars 2.0, MarketAnalytics.get_statistics() (orderbook) returned {'error': 'Analysis failed'} because argument-less pl.count() now raises:

TypeError: `pl.count()` takes at least one argument. If you want to count the number of rows, please use `pl.len()` instead.

This was the single failing test on #162 (tests/orderbook/test_orderbook_analytics.py::TestStatisticalSummaries::test_get_statistics).

Changes:

  • src/project_x_py/orderbook/analytics.py: pl.count() -> pl.len() (output column name unchanged; works on polars 1.31+ and 2.0).
  • Test asserts buy/sell trade counts.
  • CHANGELOG [Unreleased] -> Fixed.

Verified: uv run pytest tests/orderbook passes with locked polars 1.44.2 and with --with polars==2.0.0 (173 passed). No other argument-less pl.count() in src/. uv.lock unchanged.

…#162)

Polars 2.0 rejects argument-less pl.count(); get_statistics() swallowed
the TypeError as {'error': 'Analysis failed'}. Use pl.len() and keep the
output column name "count". Assert buy/sell trade counts in the existing
statistics test.
@TexasCoding
TexasCoding merged commit 4b3d553 into main Oct 15, 2026
7 checks passed
@TexasCoding
TexasCoding deleted the maint/162-polars2-pl-len branch October 16, 2026 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant