-
Notifications
You must be signed in to change notification settings - Fork 523
feat: dataframe support via narwhals
#3912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zilto
wants to merge
9
commits into
devel
Choose a base branch
from
feat/dataframe-support-via-narwhals
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a597301
add narwhals deps
zilto 1408db5
remove pandas and polars from dlt/extract/incremental/__init__
zilto a6ad157
remove pandas and polars from dlt/extract/extractors.py
zilto b2adf3d
remove pandas and polars from dlt/extract/wrappers.py
zilto 7b55df9
remove pandas and polars from dlt/extract/utils.py
zilto 35c803a
bumped narwhals version
zilto 61e510f
handle pyarrow recordbatch
zilto 5df5b4b
use native narwhals.dependencies.is_into_dataframe()
zilto a62a381
narwhals typing fix
zilto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| import narwhals | ||
|
|
||
|
|
||
| if TYPE_CHECKING: | ||
| from narwhals.typing import IntoFrame | ||
|
|
||
| from dlt.common.libs.pyarrow import pyarrow | ||
|
|
||
|
|
||
| def df_to_arrow(df: IntoFrame) -> pyarrow.Table: | ||
| """Converts any narwhals-compatible eager or lazy frame to a pyarrow table. | ||
| lazy frames are eagerly collected. | ||
| """ | ||
| nw_df = narwhals.from_native(df, allow_series=False) | ||
| if isinstance(nw_df, narwhals.LazyFrame): | ||
| nw_df = nw_df.collect() | ||
|
|
||
| return nw_df.to_arrow() |
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
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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notice that unlike
is_polars_frame,narwhals.dependencies.is_into_dataframereturns False for a polars LazyFrame (and we don't have a lazy equivalent ofis_into_dataframe- we can consider adding it to be honest, @MarcoGorelli 👀)Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks to you and Marco for the reviews! It's saving us a lot of time actually.
@FBruzzesi it would be nice to have a type guard to that catches
LazyFrame. Though, it doesn't block this PR. This polars support hasn't reachmasterbranch and isn't released yet@rudolfix IMO, the "eager arrow code path" shouldn't support lazyframes and raise "Received LazyFrame, call
.collect()inside your@dlt.resource". Currently, we're hiding an expensive operation for minimal convenience. AFAIK, we're not returningLazyFrameobjects back for downstream@dlt.transformer.Lazy objects should be supported via the "lazy model code path" where we have Ibis expressions, SQLGlot, etc. for now.
Hopefully, we can unify both by implementing load package preparations and incremental logic via Narwhals
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think calling
collecton behalf of your users would only be justified if you were doing a lot of operations lazily before reachingcollectwhich would be difficult for the user to do outside of dltinstead of calling
collectfirst thing, a clear error message like your one looks like a nice solution 👍