-
-
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
A sequence of when().then()
operations over the same set of rows applies the first when()
last
#10758
Comments
Polars
So I would not classify this as a bug, but rather a design choice. I am trying to find previous discussions on this, as I think there were, but cannot find it. Leaving open for that reason. |
#7725 was the last discussion I recall regarding this. |
Huh, I did not notice that part in the documentation, my bad for that. I can understand the design choice, but I still find it counterintuitive 🤔 Perhaps it would be worth making a note on that behavior at the beginning of the docstring? I think that would make it clearer and more noticeable. Something like this would make it clearer IMO:
|
Thank you @cmdlineluser , I even added the current explanation to the examples docstring based on that feedback, not sure why I could not find that. @rcap107 : I agree it can be put more prominent in the docstring, will move it to the upper section. |
It’s the same order as |
Checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of Polars.
Reproducible example
Result:
Issue description
I noticed that when there is a sequence of
when().then()
operations one after the other with some overlap between the rows in the condition, the final value is decided by the firstwhen().then()
rather than the last.This seems counterintuitive to me, since I would expect that the result of
pl.when(m1).then("one").when(m2).then("two").alias("c1")
would betwo
, since the block withm2
should be applied after the block with m1.Expected behavior
Result:
Installed versions
The text was updated successfully, but these errors were encountered: