-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong pl.when matching #18662
Comments
I think this came up in #18375 recently. price = pl.lit(220.92, pl.Decimal(precision=10, scale=4))
pl.select(
price = price,
true = pl.when(True).then(price / 2).otherwise(price),
false = pl.when(False).then(price / 2).otherwise(price)
)
# shape: (1, 3)
# ┌───────────────┬──────────────┬──────────────┐
# │ price ┆ true ┆ false │
# │ --- ┆ --- ┆ --- │
# │ decimal[10,4] ┆ decimal[*,8] ┆ decimal[*,8] │
# ╞═══════════════╪══════════════╪══════════════╡
# │ 220.9200 ┆ 110.46000000 ┆ 0.02209200 │
# └───────────────┴──────────────┴──────────────┘ You end up with different scale/precision even in the false case. (I don't know enough about Decimal to know what is the expected result is here.) |
Can you include the input data? Also, your output data doesn't have a If we can just copy/paste the code and run it, it is much easier to diagnose, i.e. can you also define your |
Edited code, but we can actually close it It's really decimal issue here |
Thanks--but FYI, from your edited code, we cannot see the old |
Here is test file
|
The then/otherwise values have their "supertype" computed so there is essentially an implicit cast going on. price = pl.lit(1.5)
pl.select(
price = price,
true = pl.when(True).then(pl.lit("foo")).otherwise(price),
false = pl.when(False).then(pl.lit("foo")).otherwise(price)
)
# shape: (1, 3)
# ┌───────┬──────┬───────┐
# │ price ┆ true ┆ false │
# │ --- ┆ --- ┆ --- │
# │ f64 ┆ str ┆ str │ # false=str
# ╞═══════╪══════╪═══════╡
# │ 1.5 ┆ foo ┆ 1.5 │
# └───────┴──────┴───────┘ I'm not sure if there are plans for a strict version of this operation? |
I think everything must be running in strict by default Because data must be safe and only if you are know what you are doing -- only then you should disable "strict" It's exactly the way how rust behaves, so I believe that polars must go with the same approach |
Yes, I know there are plans to change it for fill_null where a similar "gotcha" exists: #13789 pl.DataFrame({"foo": [1, None]}).select(pl.col.foo.fill_null("two"))
# shape: (2, 1)
# ┌─────┐
# │ foo │
# │ --- │
# │ str │ # <- cast
# ╞═════╡
# │ 1 │
# │ two │
# └─────┘ Perhaps the same will happen for when/then? The Decimal example was extra confusing to me as I did not realise the arithmetic operation was changing the "type". |
Checks
Reproducible example
split_date is 2020-08-31
split_to = 1
split_from = 10
Log output
Issue description
Columns are divided even when they must be not divided
Expected behavior
Columns are not divided even when they must be not divided
Installed versions
The text was updated successfully, but these errors were encountered: