Comments (6)
The query without first shouldn't be allowed. You should finish with an aggregation, or apply only element wise oprrations, otherwise the groups elements cannot be mapped to the original group.
We should raise here.
from polars.
Sounds like a plan, so an only
method for the expressions to grab the only value present in the grouped expression? e.g.
(
data_with_groups
.with_columns(
pl.col('data')
.truediv(pl.col('data').filter(pl.col('year') == 2021).only())
.over('groups')
.alias('ratio')
)
)
That would be perfect for this use case I think, then also be able to flag if there's too many or not enough filtered data points per group.
from polars.
My gut reaction to an .only
method was to scoff at it as redundant for first
but after thinking about it for a minute I think a method that assumes there will only be a single item but raises if that assumption is wrong.
It would work a little bit like expr.first(), if expr.len()!=1: raise OnlyError
from polars.
It would work a little bit like
expr.first(), if expr.len()!=1: raise OnlyError
yes exactly what i was thinking. as just using .first()
on incorrect groupings would just silently fail for this use case and i feel what im trying to accomplish is pretty foundational use case.
from polars.
@deanm0000 should I re-raise this as a feature request?
from polars.
I suppose it can't hurt.
from polars.
Related Issues (20)
- Add `mask` operations on `Expr` HOT 1
- Sorting a LazyFrame in streaming mode with a `Struct` column on a Mac, panics and then hangs HOT 1
- Make pivot args as positional instead of keyword only
- Get random state (python)
- Support native writes to s3 and gs
- Right-align numerical headers in `write_excel` HOT 2
- `write_excel(..., autofit=True)` auto-fits to source, not formatted data HOT 2
- Wrong (probably Typo) word in the output HOT 3
- Is it possible to resolve the schema, but not expand the paths when doing a `collect_schema`? HOT 2
- `unnest()` should have option to rename fields with separator HOT 3
- Converting Spark to Polars and back HOT 1
- Explanation does not match code example in User Guide / Expressions / Aggregation
- Ensure column names are unique for horizontal concat in the IR
- Expression input not working correctly for either argument of `Expr.str.replace_many` HOT 8
- PanicException on reading Parquet file from S3 HOT 4
- add an `ignore_nulls` option to `json_encode` for the `pl.Struct` column
- Change all columns one time HOT 1
- map_elements replaces all array elements with nulls
- Let arr.reshape use Expr as inputs instead of just python tuple
- Import and Export Schema Objects to JSON
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from polars.