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

未关闭
#1,064 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
42/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
data

调研方向

从 Expr 类和 issue 中引用的 functions 模块开始,然后将现有的 Expr 方法与接收表达式作为输入的函数进行比较。为适用的函数添加可链式调用的方法,同时保留 functions 模块 API;完成后,所示的 col("id1").abs().alias("id1") 模式和多输入示例应能正常工作。

由索引模型根据 Issue 内容生成。

描述

enhancement

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
Instead of doing

df.select(
    F.abs(
        col("id1")
        )
    .alias("id1")
    )

It would be nicer to do

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:

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.

主要语言
Python
星标
605
派生
176
平均合并
1 天 23 小时
30 天内合并 PR
8

贡献指南

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

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/datafusion-python 的其他 Issue

查看 apache/datafusion-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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