nodejs-polars icon indicating copy to clipboard operation
nodejs-polars copied to clipboard

Typescript types broken using `withColumn`/`withColumns`/`select` methods

Open apetta opened this issue 9 months ago • 4 comments

Have you tried latest version of polars?

  • [yes]

What version of polars are you using?

"nodejs-polars": "~0.18.0",

What operating system are you using polars on?

Mac OS Sequoia 15.3.2

What node version are you using

20.17.0

Describe your bug.

Typescript types are not correctly managed by built-in methods.

What are the steps to reproduce the behavior?

Example using withColumn Image

Example using select Image

What is the actual behavior?

As seen in the screenshots above, the types are completely wrong in both cases but in slightly different ways. withColumn totally breaks all the types, whereas select just doesn't reflect the updated types ('new_age' is missing).

What is the expected behavior?

Types should be correctly set/inferred by polars' built-in methods.

apetta avatar Mar 25 '25 14:03 apetta

@scarf005 Would you know how to fix this? Thx

Bidek56 avatar Mar 26 '25 20:03 Bidek56

@Bidek56 the issue is due to Expressions (pl.col) not being generic.

also, it'd be very hard (if not impossible) to infer correct type as we have no info on what age is before withColumn/select is called:

const age = pl.col("age")
//    ^? const c: pl.Expr<{ "age": pl.Series<unknown> }>

const mul = pl.col("age").mul(2)
//    ^? const mul: pl.Expr<{ "age": pl.Series<unknown> }>

scarf005 avatar Mar 27 '25 15:03 scarf005

@Bidek56 the issue is due to Expressions (pl.col) not being generic.

also, it'd be very hard (if not impossible) to infer correct type as we have no info on what age is before withColumn/select is called:

const age = pl.col("age") // ^? const c: pl.Expr<{ "age": pl.Series }>

const mul = pl.col("age").mul(2) // ^? const mul: pl.Expr<{ "age": pl.Series }>

I see, thank you. Would there be any way to extend the API to pass on the required type data perhaps?

Also, any guidance on where I should be looking in the repo for this stuff? Would be keen to experiment :)

apetta avatar Mar 27 '25 16:03 apetta

This is the line of code.

Bidek56 avatar Mar 27 '25 17:03 Bidek56

Hey! Is this solved?

aalpgiray avatar Aug 01 '25 16:08 aalpgiray

Hey! Is this solved?

No, per this comment I do not know how to solve it. Sorry.

Bidek56 avatar Aug 01 '25 17:08 Bidek56