pola-rs / polars

Dataframes powered by a multithreaded, vectorized query engine, written in Rust
https://docs.pola.rs
Other
29.11k stars 1.83k forks source link

Add `mask` operations on `Expr` #17838

Closed Oreilles closed 1 month ago

Oreilles commented 1 month ago

Description

It would be nice if Polars provided an equivalent to Panda's mask operations for Expr.

mask is syntactic sugar for a common replacement pattern:

pl.when(condition).then(old_expr).otherwise(new_expr)
==
old_expr.mask(condition, new_expr)
pl.when(condition).then(expr)
==
expr.mask(condition)
deanm0000 commented 1 month ago

This is probably too close to when/then/otherwise or replace/replace_strict for it to be a new feature. I'm not the decider but that's my take.

orlp commented 1 month ago

Thanks for your suggestion.

Unfortunately we've decided that we don't want this. We generally prefer to only have a single way of doing things, and expr.mask(condition) is unclear in whether the True values or False values are being masked out.