-
Notifications
You must be signed in to change notification settings - Fork 190
feat: Support concat(..., how="diagonal") for ibis
#3404
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
Changes from 5 commits
8caaf2a
f5c6407
9db77b2
7b5a3e1
cd4f50d
ceceb5b
75d5eac
a55af2d
2f76210
a8e8388
7225629
88db481
759a1f6
f2901b6
25a698b
f5a6fdc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import datetime as dt | ||
| import re | ||
|
|
||
| import pytest | ||
|
|
||
| import narwhals as nw | ||
| from narwhals._utils import Implementation | ||
| from narwhals.exceptions import InvalidOperationError | ||
| from tests.utils import Constructor, ConstructorEager, assert_equal_data | ||
|
|
||
|
|
@@ -61,11 +63,7 @@ def test_concat_vertical(constructor: Constructor) -> None: | |
| nw.concat([df_left, df_left.select("d")], how="vertical").collect() | ||
|
|
||
|
|
||
| def test_concat_diagonal( | ||
| constructor: Constructor, request: pytest.FixtureRequest | ||
| ) -> None: | ||
| if "ibis" in str(constructor): | ||
| request.applymarker(pytest.mark.xfail) | ||
| def test_concat_diagonal(constructor: Constructor) -> None: | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@FBruzzesi okay this led to discovering a bug (but not in any of the new code or your suggestion)
I found that out by using the 3-tabled version of the test: That fails for Show test
def test_concat_vertical_bigger(constructor: Constructor) -> None:
data_1 = {"a": [1, 2], "b": [3, 4], "c": [0, None]}
data_2 = {"a": [5, 6], "b": [0, None], "c": [7, 8]}
data_3 = {"a": [0, None], "b": [9, 10], "c": [11, 12]}
expected = {
"a": [1, 2, 5, 6, 0, None],
"b": [3, 4, 0, None, 9, 10],
"c": [0, None, 7, 8, 11, 12],
}
df_1 = nw.from_native(constructor(data_1)).lazy()
df_2 = nw.from_native(constructor(data_2)).lazy()
df_3 = nw.from_native(constructor(data_3)).lazy()
result = nw.concat([df_1, df_2, df_3], how="vertical")
assert_equal_data(result, expected)Show error
E AssertionError: Mismatch at index 0, key a: 0 != 1
E Expected: {'a': [1, 2, 5, 6, 0, None], 'b': [3, 4, 0, None, 9, 10], 'c': [0, None, 7, 8, 11, 12]}
E Got: {'a': [0, None, 5, 6, 1, 2], 'b': [9, 10, 0, None, 3, 4], 'c': [11, 12, 7, 8, 0, None]}
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For a moment I thought order of columns, and I panicked sooo much 🤯 No guarantee in row order makes sense. You can add an index column and sort by such |
||
| data_1 = {"a": [1, 3], "b": [4, 6]} | ||
| data_2 = {"a": [100, 200], "z": ["x", "y"]} | ||
| expected = { | ||
|
|
@@ -83,3 +81,25 @@ def test_concat_diagonal( | |
|
|
||
| with pytest.raises(ValueError, match="No items"): | ||
| nw.concat([], how="diagonal") | ||
|
|
||
|
|
||
| def test_concat_diagonal_invalid( | ||
| constructor: Constructor, request: pytest.FixtureRequest | ||
| ) -> None: | ||
| data_1 = {"a": [1, 3], "b": [4, 6]} | ||
| data_2 = { | ||
| "a": [dt.datetime(2000, 1, 1), dt.datetime(2000, 1, 2)], | ||
| "b": [4, 6], | ||
| "z": ["x", "y"], | ||
| } | ||
| df_1 = nw.from_native(constructor(data_1)).lazy() | ||
| bad_schema = nw.from_native(constructor(data_2)).lazy() | ||
| impl = df_1.implementation | ||
| request.applymarker( | ||
| pytest.mark.xfail( | ||
| impl not in {Implementation.IBIS, Implementation.POLARS}, | ||
| reason=f"{impl!r} does not validate schemas for `concat(how='diagonal')", | ||
| ) | ||
| ) | ||
|
dangotbanned marked this conversation as resolved.
|
||
| with pytest.raises((InvalidOperationError, TypeError), match=r"same schema"): | ||
| nw.concat([df_1, bad_schema], how="diagonal").collect().to_dict(as_series=False) | ||
Uh oh!
There was an error while loading. Please reload this page.