-
Notifications
You must be signed in to change notification settings - Fork 175
feat: Add narwhals.struct top level function
#3261
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
msalvany
wants to merge
30
commits into
narwhals-dev:main
Choose a base branch
from
msalvany:issue_3247
base: main
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.
+202
β3
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
6900283
ADD `concat_struct` for pandas_like
msalvany c15443f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4bb8a1e
remove TODO comment
msalvany 1761bc7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3679569
ADD `concat_struct` for polars
msalvany 934b113
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 36a49a8
ADD concat_struct for arrow
msalvany 88a8fa3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] eeaa3dc
ADD dry-run test
msalvany 41b201d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d9e70d3
removed duplicated raise
msalvany 9cdf7ac
Change `concat_struct` to `struct`in all files
msalvany c1b6481
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 76b0267
Add `struct = not_implemented()` for dask", duckdb, ibis, pyspark, sqβ¦
msalvany 7e1fc08
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d8b4af9
remove 'print' from test.py
msalvany 41f4b87
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 661a29c
TypeError for pandas_like namespace
msalvany ad855a5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 9fa78ab
test_struct: `assert_equal_data(result, expected)`
msalvany c9d4b0c
doctstring example test passed
msalvany 75f5b77
add `struct` to api-reference top-level functions
msalvany 561aaf0
TypeError improvement
msalvany 0ecf99f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ad2bbea
imports update for pandas namespace
msalvany 2475cd1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d58cd73
remove folder
msalvany 5539438
pandas_like supporting NaN values test check
msalvany 64db266
updated docstring example in v2 (test passed)
msalvany 04e828a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
|
|
||
| import narwhals as nw | ||
| from tests.utils import POLARS_VERSION, Constructor, assert_equal_data | ||
|
|
||
| pytest.importorskip("pyarrow") | ||
|
|
||
| data = {"a": [1, 2, 3], "b": ["dogs", "cats", None], "c": ["play", "swim", "walk"]} | ||
|
|
||
|
|
||
| def test_struct(constructor: Constructor, *, request: pytest.FixtureRequest) -> None: | ||
| if "polars" in str(constructor) and POLARS_VERSION < (1, 0, 0): | ||
| request.applymarker(pytest.mark.xfail) | ||
| if any( | ||
| x in str(constructor) for x in ("dask", "duckdb", "ibis", "pyspark", "sqlframe") | ||
| ): | ||
| request.applymarker(pytest.mark.xfail(reason="Not supported / not implemented")) | ||
|
|
||
| df = nw.from_native(constructor(data)) | ||
| result = df.select(nw.struct([nw.col("a"), nw.col("b"), nw.col("c")]).alias("struct")) | ||
|
|
||
| expected = { | ||
| "struct": [ | ||
| {"a": 1, "b": "dogs", "c": "play"}, | ||
| {"a": 2, "b": "cats", "c": "swim"}, | ||
| {"a": 3, "b": None, "c": "walk"}, | ||
| ] | ||
| } | ||
|
|
||
| assert_equal_data(result, expected) |
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.
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.
quick note that
tolistand iterating over values in Python isn't allowed here, as it's very inefficient - you'll need to look for a way to do this using the pandas apiThere 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.
Hey @msalvany - what's the main reason behind this check in the first place? I thought we might be able to get away without it π