Skip to content

fix: reject eager_only with an already-narwhals LazyFrame#3677

Open
gaoflow wants to merge 1 commit into
narwhals-dev:mainfrom
gaoflow:fix/3226-from-native-narwhals-lazy-eager-only
Open

fix: reject eager_only with an already-narwhals LazyFrame#3677
gaoflow wants to merge 1 commit into
narwhals-dev:mainfrom
gaoflow:fix/3226-from-native-narwhals-lazy-eager-only

Conversation

@gaoflow

@gaoflow gaoflow commented Jun 10, 2026

Copy link
Copy Markdown

Closes #3226.

from_native has an early-return for an object that is already a narwhals DataFrame/LazyFrame, returning it before the eager_only / eager_or_interchange_only validation runs (_translate_if_compliant enforces it, but the early return skips that path). So a native pl.LazyFrame was correctly rejected:

nw.from_native(pl.LazyFrame(), eager_only=True)  # TypeError ✅

but an already-narwhals one slipped through and was returned unchanged:

lf = nw.from_native(pl.LazyFrame())
nw.from_native(lf, eager_only=True)  # returned the LazyFrame ❌ (should raise)

This adds the same guard in the early-return path: a narwhals LazyFrame with eager_only/eager_or_interchange_only now raises (or is returned unchanged under pass_through=True), while a narwhals DataFrame (which is eager) is still accepted. Regression test added (fails on main).

One note: narwhals.stable.v1.from_native has the same early-return short-circuit (before it calls _from_native_impl), so the v1 entrypoint still passes a narwhals LazyFrame through. I left v1 untouched since it's the frozen stable API and the fix there needs the pass_through resolution moved above the early return — happy to apply the same guard there if you'd like.

`from_native` short-circuits when given an object that is already a narwhals
DataFrame/LazyFrame, returning it before the `eager_only` /
`eager_or_interchange_only` validation runs. A native polars LazyFrame is
correctly rejected, but an already-narwhals one slipped through. Enforce the
same check in the early-return path.

Closes narwhals-dev#3226
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.

from_native(nw.LazyFrame, eager_only=True) returns nw.LazyFrame

1 participant