Giter Site home page Giter Site logo

Comments (6)

ritchie46 avatar ritchie46 commented on July 26, 2024

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.

Andre-Medina avatar Andre-Medina commented on July 26, 2024

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.

deanm0000 avatar deanm0000 commented on July 26, 2024

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.

Andre-Medina avatar Andre-Medina commented on July 26, 2024

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.

Andre-Medina avatar Andre-Medina commented on July 26, 2024

@deanm0000 should I re-raise this as a feature request?

from polars.

deanm0000 avatar deanm0000 commented on July 26, 2024

I suppose it can't hurt.

from polars.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.