apache / apache/datafusion-python

Add most functions to the Expr class so that they're chainable.

未关闭
#1,064 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
enhancement
主要语言
Python
星标
604
派生
174
平均合并
1 天 7 小时
30 天内合并 PR
4

描述

**Is your feature request related to a problem or challenge? Please describe what you are trying to do.**
Instead of doing
```python
df.select(
F.abs(
col("id1")
)
.alias("id1")
)
```

It would be nicer to do

```python
df.select(
col("id1")
.abs()
.alias("id1")
)
```

**Describe the solution you'd like**
This is already partly there, for example, `alias` is already in the Expr class. It would be a bit tedious but easy to add under `class Expr`, for example:

```python
def abs(self) -> datafusion.Expr:
"""Return the absolute value of a given number.

Returns:
--------
Expr
A new expression representing the absolute value of the input expression.
"""
return F.abs(self)
```

**Describe alternatives you've considered**
if it weren't for the type hinter, monkey patching.

**Additional context**
There will still be functions that don't make sense to chain off of a call to `col` such as `when` since it doesn't return an Expr. But, even functions that take multiple inputs can have this for instance `col("a").atan2("b")`. Additionally, this is completely backwards compatible since I'm not proposing eliminating the functions module.

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。