Skip to content

Latest commit

 

History

History
57 lines (48 loc) · 1.97 KB

README.md

File metadata and controls

57 lines (48 loc) · 1.97 KB

Narwhals-daft

Narwhals plugin for Daft!

See Narwhals for Narwhals documentation and API. This plugin allows Narwhals to accept Daft inputs (in addition to all the inputs it already accepts).

Installation

pip install narwhals-daft

Example

import daft
import narwhals as nw
from narwhals.typing import IntoFrameT

data = {
    "animal": [
        "penguin",
        "dodo",
        "beluga",
        "narwhal",
        "cat",
        "dog",
        "hamster",
        "falcon",
    ],
    "awesomeness": [7, 5, 8, 15, 5, 4, 3, 9],
}
df_daft = daft.from_pydict(data)
df = nw.from_native(df_daft)
result = df.with_columns(
    relative_awesomeness=nw.col("awesomeness") / nw.col("awesomeness").max()
).filter(nw.col("relative_awesomeness") > 0.5)
print(result.to_native().collect())
╭─────────┬─────────────┬──────────────────────╮
│ animal  ┆ awesomeness ┆ relative_awesomeness │
│ ---     ┆ ---         ┆ ---                  │
│ String  ┆ Int64       ┆ Float64              │
╞═════════╪═════════════╪══════════════════════╡
│ beluga  ┆ 8           ┆ 0.5333333333333333   │
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ narwhal ┆ 15          ┆ 1                    │
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ falcon  ┆ 9           ┆ 0.6                  │
╰─────────┴─────────────┴──────────────────────╯

(Showing first 3 of 3 rows)