pola-rs / nodejs-polars

nodejs front-end of polars
https://pola-rs.github.io/nodejs-polars/
MIT License
343 stars 36 forks source link

generic signature for dataframes and series #151

Open scarf005 opened 6 months ago

scarf005 commented 6 months ago

Motivation

Feature Request

As-is

import pl from "npm:nodejs-polars"

const df = pl.DataFrame({
    fruit: ["Apples", "Oranges"],
    comparability: [0, 1],
})
// df: pl.DataFrame

const obj = df.toObject()
// obj: Record<string, any[]>

const fruit = df.getColumn('fruit')
// fruit: pl.Series

To-be

import pl from "npm:nodejs-polars"

const df = pl.DataFrame({
    fruit: ["Apples", "Oranges"],
    comparability: [0, 1],
})
// df: pl.DataFrame<{ fruit: pl.Series<"Utf8">, comparability: pl.Series<"Float64"> }>

const obj = df.toObject()
// obj: { fruit: string[], comparability: number[] }

const fruit = df.getColumn('fruit')
// fruit: pl.Series<"Float64">

Additional notes

I'm interested in opening a PR.

See also

Bidek56 commented 6 months ago

@scarf005 Feel free to put a PR in, if you need help please reach out on Discord. Thx

universalmind303 commented 6 months ago

I think this is an interesting idea, and one that I have considered as well.

There are some considerations to take into account though. the python & rust implementations both use an untyped Series and DataFrame, so this does cause some deviation from the other implementations, but that may be okay. I'd be happy to review a POC & see what it looks like though!