You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "milenkovicm (via GitHub)" <gi...@apache.org> on 2025/10/13 17:18:34 UTC
[PR] feat: expose `select_exprs` method on DataFrame [datafusion-python]
milenkovicm opened a new pull request, #1271:
URL: https://github.com/apache/datafusion-python/pull/1271
# Which issue does this PR close?
Closes #.
# Rationale for this change
Expose DataFrame.select_exprs method, which is supported in DataFusion, this method is similar to [pyspark.select_expr](https://spark.apache.org/docs/latest/api/python/reference/pyspark.sql/api/pyspark.sql.DataFrame.selectExpr.html)
Method will parse string expressions into logical plan expressions, making easier to create select statements when expressions are involved
```python
df_3 = df.select_exprs(
"abs(a + b)",
"abs(a - b)",
)
```
It would be ideal if we could support expressions on df.select(...) but that change looked as a bit complicated for me.
# What changes are included in this PR?
- new method exposed
- test to cover it
# Are there any user-facing changes?
- additional method has been added
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: expose `select_exprs` method on DataFrame [datafusion-python]
Posted by "milenkovicm (via GitHub)" <gi...@apache.org>.
milenkovicm commented on code in PR #1271:
URL: https://github.com/apache/datafusion-python/pull/1271#discussion_r2426935452
##########
python/datafusion/dataframe.py:
##########
@@ -404,6 +404,15 @@ def select_columns(self, *args: str) -> DataFrame:
DataFrame only containing the specified columns.
"""
return self.select(*args)
+
+ def select_exprs(self, *args: str) -> DataFrame:
+ """Project arbitrary list of expression strings into a new DataFrame. Method will parse string expressions into logical plan expressions.
+ The output DataFrame has one column for each element in exprs.
+
+ Returns:
+ DataFrame only containing the specified columns.
+ """
+ return self.df.select_exprs(*args)
Review Comment:
changed, will follow up later if it fails
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: expose `select_exprs` method on DataFrame [datafusion-python]
Posted by "timsaucer (via GitHub)" <gi...@apache.org>.
timsaucer commented on PR #1271:
URL: https://github.com/apache/datafusion-python/pull/1271#issuecomment-3398899499
I fixed the lint error. Thank you for the PR! I will merge as soon as I see CI finish.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: expose `select_exprs` method on DataFrame [datafusion-python]
Posted by "milenkovicm (via GitHub)" <gi...@apache.org>.
milenkovicm commented on PR #1271:
URL: https://github.com/apache/datafusion-python/pull/1271#issuecomment-3398938484
you were three minutes faster than me fixing it :) thanks @timsaucer
as a follow up I filled https://github.com/apache/datafusion-python/issues/1273
maybe we could expose
```
DataFrame.parse_sql_expr(e)
```
as a first step, not sure what do you think ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: expose `select_exprs` method on DataFrame [datafusion-python]
Posted by "timsaucer (via GitHub)" <gi...@apache.org>.
timsaucer merged PR #1271:
URL: https://github.com/apache/datafusion-python/pull/1271
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: expose `select_exprs` method on DataFrame [datafusion-python]
Posted by "timsaucer (via GitHub)" <gi...@apache.org>.
timsaucer commented on code in PR #1271:
URL: https://github.com/apache/datafusion-python/pull/1271#discussion_r2426918410
##########
python/datafusion/dataframe.py:
##########
@@ -404,6 +404,15 @@ def select_columns(self, *args: str) -> DataFrame:
DataFrame only containing the specified columns.
"""
return self.select(*args)
+
+ def select_exprs(self, *args: str) -> DataFrame:
+ """Project arbitrary list of expression strings into a new DataFrame. Method will parse string expressions into logical plan expressions.
+ The output DataFrame has one column for each element in exprs.
+
+ Returns:
+ DataFrame only containing the specified columns.
+ """
+ return self.df.select_exprs(*args)
Review Comment:
I think this will fail the `ruff` linter
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: expose `select_exprs` method on DataFrame [datafusion-python]
Posted by "milenkovicm (via GitHub)" <gi...@apache.org>.
milenkovicm commented on PR #1271:
URL: https://github.com/apache/datafusion-python/pull/1271#issuecomment-3398453057
thanks @timsaucer
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org