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

fix(python): silence Series.apply inefficient apply warning when calling Expr.apply #10116

Conversation

MarcoGorelli
Copy link
Collaborator

@MarcoGorelli MarcoGorelli commented Jul 27, 2023

The warning's currently being shown twice, once from Expr.apply and once from Series.apply :

In [1]: my_dict = {1: "1", 2: "2", 3: "3"}
   ...: df = pl.DataFrame({"a": [1, 2, 3]})
   ...: df.select(pl.col("a").apply(lambda x: x**2))
   ...: 
<ipython-input-1-2741e0b26152>:3: PolarsInefficientApplyWarning: 
Expr.apply is significantly slower than the native expressions API.
Only use if you absolutely CANNOT implement your logic otherwise.
In this case, you can replace your `apply` with the following:
  -  pl.col("a").apply(lambda x: ...)
  +  pl.col("a") ** 2

  df.select(pl.col("a").apply(lambda x: x**2))
sys:1: PolarsInefficientApplyWarning: 
Series.apply is significantly slower than the native series API.
Only use if you absolutely CANNOT implement your logic otherwise.
In this case, you can replace your `apply` with the following:
  -  s.apply(lambda x: ...)
  +  s ** 2

Out[1]: 
shape: (3, 1)
┌─────┐
│ a   │
│ --- │
│ i64 │
╞═════╡
│ 1   │
│ 4   │
│ 9   │
└─────┘

Adding a test to check the exact warning message so this doesn't happen again

@github-actions github-actions bot added fix Bug fix python Related to Python Polars labels Jul 27, 2023
@MarcoGorelli MarcoGorelli marked this pull request as draft July 27, 2023 14:52
@MarcoGorelli MarcoGorelli marked this pull request as ready for review July 27, 2023 14:56
@alexander-beedie alexander-beedie merged commit 7060670 into pola-rs:main Jul 27, 2023
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants