Skip to content

MNT polars 1.40 deprecated dataframe interchange protocol __dataframe__ - #33789

Merged
jeremiedbb merged 4 commits into
scikit-learn:mainfrom
lorentzenchr:polars_deprecate__dataframe__
Apr 23, 2026
Merged

jeremiedbb merged 4 commits into
scikit-learn:mainfrom
lorentzenchr:polars_deprecate__dataframe__

Conversation

@lorentzenchr

Copy link
Copy Markdown
Member

Reference Issues/PRs

None

What does this implement/fix? Explain your changes.

Polars version 1.40 deprecated the dataframe interchange protocol __dataframe__, see https://github.com/pola-rs/polars/releases/tag/py-1.40.0.
This PR makes polars code path not relying on it.

AI usage disclosure

None

Any other comments?

We could treat string columns in HistGradientBoosting* as categorical....

@ogrisel ogrisel 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.

Thanks. LGTM.

@ogrisel

ogrisel commented Apr 20, 2026

Copy link
Copy Markdown
Member

I think we might want to add a changelog entry because the code change is not trivial.

@lorentzenchr

Copy link
Copy Markdown
Member Author

I think we might want to add a changelog entry because the code change is not trivial.

A fix?

@ogrisel

ogrisel commented Apr 20, 2026 •

Copy link
Copy Markdown
Member

BTW, I confirm that this should fix our circle CI build in #33804 as the following fails with main but passes with this branch (when running with polars 1.40.0):

python -Werror examples/applications/plot_time_series_lagged_features.py

@lorentzenchr

lorentzenchr commented Apr 20, 2026 •

Copy link
Copy Markdown
Member Author

I think the HistGradientBoosting* path is unchanged behavior (not an improvement but also no deterioration):

import polars as pl

df = pl.DataFrame({
    "a": [1, 2],
    "b": ["a", "b"],
    "c": pl.Series(["a", "b"], dtype=pl.Enum(["a", "b"])),
    "d": pl.Series(["a", "b"], dtype=pl.Categorical)
})
idf = df.__dataframe__()
[c.dtype for c in idf.get_columns()]
# Out[8]: 
# [(<DtypeKind.INT: 0>, 64, 'l', '='),
# (<DtypeKind.STRING: 21>, 8, 'U', '='),
# (<DtypeKind.CATEGORICAL: 23>, 32, 'I', '='),
# (<DtypeKind.CATEGORICAL: 23>, 32, 'I', '=')]

So pl.Enum was already treated as categorical.

@ogrisel ogrisel added the Quick Review For PRs that are quick to review label Apr 20, 2026

@virchan virchan 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! Thanks, @lorentzenchr!

@ogrisel, could we merge this?

Edit: Waiting to reach consensus in #31049.

@jeremiedbb

Copy link
Copy Markdown
Member

The consensus is roughly to switch to narwhals but still merge this PR as a temporary fix

@jeremiedbb
jeremiedbb merged commit c054af3 into scikit-learn:main Apr 23, 2026
38 checks passed
@lorentzenchr
lorentzenchr deleted the polars_deprecate__dataframe__ branch April 24, 2026 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants