-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
fix: output name of ternary expr #12381
Conversation
truthy.len() | ||
let len = truthy.len(); | ||
*falsy = match falsy.len() < len { | ||
true => Series::full_null(falsy.name(), len, falsy.dtype()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we write this in terms of if else
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah
*truthy = falsy.clone(); | ||
falsy.len() | ||
let len = falsy.len(); | ||
*truthy = match truthy.len() < len { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idem
@ritchie46 - just had a realization that it is probably not a good idea to be broadcasting to the matching branch... I think instead it's better to maintain the previous behavior (i.e. require all branches to have the same height and error otherwise) - otherwise we get: df = pl.DataFrame(
{"x": range(5), "y": range(5, 10)}, schema={"x": pl.Int8, "y": pl.Int64}
).with_columns(true=True, false=False)
df.select(pl.when(pl.first("true")).then(pl.col("x")))
# shape: (5, 1)
# ┌─────┐
# │ x │
# │ --- │
# │ i8 │
# ╞═════╡
# │ 0 │
# │ 1 │
# │ 2 │
# │ 3 │
# │ 4 │
# └─────┘
df.select(pl.when(pl.first("false")).then(pl.col("x")))
# we get this if we broadcast to the matching branch (on 0.19.13):
# >>> df.select(pl.when(pl.first("false")).then(pl.col("x")))
# shape: (1, 1)
# ┌──────┐
# │ x │
# │ --- │
# │ i8 │
# ╞══════╡
# │ null │
# └──────┘
# but it should probably instead be this (on 0.19.12):
# shape: (5, 1)
# ┌──────┐
# │ x │
# │ --- │
# │ i8 │
# ╞══════╡
# │ null │
# │ null │
# │ null │
# │ null │
# │ null │
# └──────┘ So I think instead it's probably better to have #12357 to be reverted instead of merging this (or I can adjust this PR as well to remove the special broadcasting) - @JulianCologne raises a good point in #12363, a better fix for the original issue (#12354) is probably to have *as a note, the current change in behavior in |
Yes, let's revert this and fix |
Fixes issue #12380 (introduced by #12357).
The previous PR lost the series name and dtype for the non-matching branch, but they need to be preserved to have the correct output name and dtype even if the values are never used.