apache / apache/datafusion-python
Add most functions to the Expr class so that they're chainable.
- Linguagem predominante
- Python
- Estrelas
- 604
- Forks
- 174
- Merge médio
- 2d 22h
- PRs com merge (30d)
- 5
Descrição
**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.
Guia de contribuição
Nenhum guia de contribuição indexado para este repositório
Direção de pesquisa
Comece pela classe Expr e pelo módulo functions referenciado na issue; depois compare os métodos existentes de Expr com as funções que recebem uma expressão como entrada. Adicione métodos encadeáveis para as funções aplicáveis, mantendo a API do módulo functions; o padrão mostrado col("id1").abs().alias("id1") e o exemplo com múltiplas entradas devem funcionar ao final.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- data
- Tipo de issue
- Funcionalidade
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 42/100