You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Those inconsistent 0-size results can cause multiple problems.
A recent one (#12354) was already fixed (#12357) by adding extra logic to when/then but the real problem was actually first returning a 0-size result. By fixing the return value of first no extrac logic is required.
Expected behavior
first / last should behave like other aggreation functions and return a consistent size output (1 element) even if the column is empty!
correct: [].first -> null
wrong: [].first -> 0-size df
Installed versions
0.19.12
The text was updated successfully, but these errors were encountered:
I see your point. My only concern is that this could easily make it seem like the first element of this column is Null instead of empty. After all, first and last have such meanings.
I see your point. My only concern is that this could easily make it seem like the first element of this column is Null instead of empty. After all, first and last have such meanings.
good point!
However, I think being consistent and always returning a value is better for the user.
This "problem" can lead to bugs/panics/crashes that the user cannot control.
The ambiguity is not allways avoidable but also consistent with the other functions.
[].std = null
[null, null].std = null
What the user can do is drop_nulls() before and when the result is null you know it is empty
I think there are some differences between first/last and std/mean etc. It clearly indicates the element at the specific position, but the others do not.
But I truly understand the benefits of being consistent with other agg funcs. So I don't have a strong tendency. :)
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
Log output
No response
Issue description
first
/last
should behave like other aggreation functions and return a consistent size output (1 element) even if the column is empty!Empty column behaviour examples:
sum
->0
std
->null
str.concat
->""
(was recently fixed: fix(python,rust): str.concat on empty list #12066)BUT
first
-> empy zero length df but should benull
Those inconsistent 0-size results can cause multiple problems.
A recent one (#12354) was already fixed (#12357) by adding extra logic to
when/then
but the real problem was actuallyfirst
returning a 0-size result. By fixing the return value offirst
no extrac logic is required.Expected behavior
first
/last
should behave like other aggreation functions and return a consistent size output (1 element) even if the column is empty![].first
->null
[].first
-> 0-size dfInstalled versions
The text was updated successfully, but these errors were encountered: