Skip to content

fix: breaking change in pl.from_arrow in polars 2.x - #187

Merged
nvictus merged 5 commits into
abdenlab:mainfrom
StefanoCretti:main
Nov 17, 2026
Merged

nvictus merged 5 commits into
abdenlab:mainfrom
StefanoCretti:main

Conversation

@StefanoCretti

Copy link
Copy Markdown
Contributor

In polars 1.x, calling pl.from_arrow on an arro3 RecordBatch object yields a DataFrame.
In polars 2.x, the same call returns a struct of Series.
This caused any reader yielding a LazyFrame to raise.

Fixed by explicit DataFrame casting instead of from_arrow (also works in 1.x).
Also fixed same pattern in documentation code snippet and its description.
Updated test suite to test against polars 2.x (before only 1.x).

Fixes #186

Oxbow readers are implemented using pyo3-arrow. In Python, the reader batches are returned as arro3.core.RecordBatch objects, which are not recognized as pyarrow objects for pl.from_arrow.
In polars 1.x, arro3 batches where converted to dataframes with a warning.
In polars 2.x, arro3 batches are converted to a struct of series, which is a different type and causes a raise.
Fixed by explicit casting to DataFrame, which does not cause performance degradation and is backwards compatible.
The test used pyarrow batches, which polars 2.x treats slightly differently than the arro3 ones (which are the ones that the built-in readers from oxbow actually return). Without this change, tests could false negative errors due to changes in polars 2.x.
Without updating uv lock, only versions 1.x of polars would be tested, causing issues with 2.x to be missed.
Addressed same bug in the example code, by casting to DataFrame instead.
Also, fixed misleading dtype declaration in docs.

Note: polars 2.x changes default rendering of lf.show_graph(). As no text in the documentation refers to its content, accepted the change silently.
Several packages do not have wheels for 3.14 at the moment, which would require major changes to the lock file. Trying by temporarily pinning to an older version instead.

@nvictus nvictus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nvictus
nvictus merged commit d504462 into abdenlab:main Nov 17, 2026
8 checks passed
@nvictus

nvictus commented Nov 17, 2026

Copy link
Copy Markdown
Member

Thank you, @StefanoCretti!

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.

LazyFrame issue with BigBedFile

2 participants