feat: Add Expr.item to strictly extract a single value from an expression#24888
Conversation
Expr.single to strictly extract a single value from an expressionExpr.single to strictly extract a single value from an expression
| Traceback (most recent call last): | ||
| ... ComputeError: cannot unpack single value from list of length 2 | ||
| """ | ||
| return wrap_expr(self._pyexpr.list_single()) |
There was a problem hiding this comment.
I think list.single() can be implemented with the same perf as list.agg(pl.element().single()).
|
Also fixes #21856 (the list variant) |
|
If we decide to go with single, I think we should rename |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #24888 +/- ##
==========================================
+ Coverage 81.76% 81.82% +0.05%
==========================================
Files 1700 1700
Lines 233868 234045 +177
Branches 2997 2997
==========================================
+ Hits 191219 191501 +282
+ Misses 41884 41779 -105
Partials 765 765 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@ritchie46 The inconvenient thing about |
ac02ad9 to
3870eeb
Compare
| IRAggExpr::Implode(node) | ||
| | IRAggExpr::First(node) | ||
| | IRAggExpr::Last(node) | ||
| | IRAggExpr::Single(node) => { |
There was a problem hiding this comment.
Missed optimization - Single doesn't observe ordering - it only observes length.
It should be in a separate branch that just returns O::None (i.e. no observable orderings, since we are returning a scalar in the Ok(_) case).
|
I am not a huge fan of I like |
|
#24475 suggested the name |
The problem is that |
a5b3234 to
de4f8df
Compare
|
@MarcoGorelli It's more that there is a mismatch between |
coastalwhite
left a comment
There was a problem hiding this comment.
nice, a few small changes.
|
Ai, this was merged a bit too early. :') Not a big deal, will work around it. |
List of all changes
Expr.item()to select the only item from anExpr. In other words: it is likeExpr.first()but it will raise an error ifExprdoes not contain a single valueList.item(), for listsAddDataFrame.item()on dataframesAddSeries.item()on seriesDeprecateDataFrame.item()in favor ofDataFrame.single()andDataFrame[row, col]DeprecateSeries.item()in favor ofSeries.single()andSeries[index]Review suggestions
Issinglethe correct name? Or should we consider another name?item()Still Todo
Expr.itemdocs that it does not take arguments, and that if the user wants item retrieval, they should useExpr.getFixes: #8689
Fixes: #21856
Related issue: #24475