I was working on fixing a bug in my data pipeline and i noticed i was getting unexpected values for a column,
I have abstracted the operation into a simple dataframe with 4 rows for the sake of replicating the bug.
Basically the condtion for the last row is not working as expected,
Comparing a NaN value should yeild False for the first 2 condtions, yet I still end up with the first condition passing through.
Code -
import numpy as np
import polars as pl
data = {
'x' : [1,2,3,4],
'y' : [4.33,-4,54.7,np.NaN]
}
df = pl.DataFrame(data)
df2 = df.with_columns(
pl.when(pl.col('y') > 0.02).then(pl.lit('P'))
.when(pl.col('y') < -0.02).then(pl.lit('Q'))
.otherwise(None).alias('z')
)
df2