Skip to content
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

Request for rolling_top_k #16266

Open
leoknuth opened this issue May 16, 2024 · 1 comment
Open

Request for rolling_top_k #16266

leoknuth opened this issue May 16, 2024 · 1 comment
Labels
enhancement New feature or an improvement of an existing feature

Comments

@leoknuth
Copy link

Description

Request for a rolling_top_k expression.

Currently, I can do this with very slow code using rolling_map and lambda.

data = data.with_columns(
    roll_top_k_mean = pl.col("a").rolling_map(lambda x: x.top_k(5).mean(), window_size=10)
)

The method I hope to use is like:

data = data.with_columns(
    roll_top_k_mean = pl.col("a").rolling_top_k(k=5, w=10).mean()
)

You can use 2 heaps and 1 queue to implement this.

@leoknuth leoknuth added the enhancement New feature or an improvement of an existing feature label May 16, 2024
@cmdlineluser
Copy link
Contributor

As an aside, I think the slow rolling_map can be replaced with Expr.rolling - right?

(data
  .with_row_index()
  .with_columns(
      pl.col("a").top_k(5).mean().rolling(index_column="index", period="5i")
  )
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants