fix: reject eager_only with an already-narwhals LazyFrame#3677
Open
gaoflow wants to merge 1 commit into
Open
Conversation
`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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3226.
from_nativehas an early-return for an object that is already a narwhalsDataFrame/LazyFrame, returning it before theeager_only/eager_or_interchange_onlyvalidation runs (_translate_if_compliantenforces it, but the early return skips that path). So a nativepl.LazyFramewas correctly rejected:but an already-narwhals one slipped through and was returned unchanged:
This adds the same guard in the early-return path: a narwhals
LazyFramewitheager_only/eager_or_interchange_onlynow raises (or is returned unchanged underpass_through=True), while a narwhalsDataFrame(which is eager) is still accepted. Regression test added (fails onmain).One note:
narwhals.stable.v1.from_nativehas the same early-return short-circuit (before it calls_from_native_impl), so the v1 entrypoint still passes a narwhalsLazyFramethrough. I left v1 untouched since it's the frozen stable API and the fix there needs thepass_throughresolution moved above the early return — happy to apply the same guard there if you'd like.