-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add .select (by str) for duckdb and ibis
- Loading branch information
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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,46 @@ | ||
from __future__ import annotations | ||
|
||
import duckdb | ||
import polars as pl | ||
import pytest | ||
|
||
import narwhals.stable.v1 as nw | ||
|
||
data = {"a": [1, 2, 3], "b": [4.0, 5.0, 6.1], "z": ["x", "y", "z"]} | ||
|
||
|
||
def test_interchange() -> None: | ||
df_pl = pl.DataFrame(data) | ||
df = nw.from_native(df_pl.__dataframe__(), eager_or_interchange_only=True) | ||
with pytest.raises( | ||
NotImplementedError, | ||
match="Attribute select is not supported for metadata-only dataframes", | ||
): | ||
df.select("a", "z") | ||
|
||
|
||
def test_interchange_ibis( | ||
tmpdir: pytest.TempdirFactory, | ||
) -> None: # pragma: no cover | ||
ibis = pytest.importorskip("ibis") | ||
df_pl = pl.DataFrame(data) | ||
|
||
filepath = str(tmpdir / "file.parquet") # type: ignore[operator] | ||
df_pl.write_parquet(filepath) | ||
|
||
tbl = ibis.read_parquet(filepath) | ||
df = nw.from_native(tbl, eager_or_interchange_only=True) | ||
|
||
out_cols = df.select("a", "z").schema.names() | ||
|
||
assert out_cols == ["a", "z"] | ||
|
||
|
||
def test_interchange_duckdb() -> None: | ||
df_pl = pl.DataFrame(data) # noqa: F841 | ||
rel = duckdb.sql("select * from df_pl") | ||
df = nw.from_native(rel, eager_or_interchange_only=True) | ||
|
||
out_cols = df.select("a", "z").schema.names() | ||
|
||
assert out_cols == ["a", "z"] |