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
平均合併
2 天 22 小時
30 天內合併 PR
5

描述

**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.

貢獻指南

這個儲存庫沒有索引到貢獻指南

研究方向

從 Expr 類別和 issue 中參照的 functions 模組開始,然後比較現有的 Expr 方法與將表達式作為輸入的函式。為適用的函式新增可鏈式呼叫的方法,同時保留 functions 模組 API;完成後,所示的 col("id1").abs().alias("id1") 模式和多輸入範例應能正常運作。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
data
Issue 類型
功能
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。