Allow decorator use for functions defined in other modules

Abierto
#1,281 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 7 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python

Línea de trabajo

Comienza con la reproducción en my_module/init.py, base.py, base_extended.py y run.py, centrándote en hamilton.function_modifiers.parameterize y en cómo driver.Builder().with_modules() descubre las funciones. Reproduce los errores de definición duplicada y de nodo faltante; después, rastrea si decorar base.a cambia la función independiente. Se considera terminado cuando las funciones importadas decoradas funcionan sin duplicar ni eliminar el nodo original del grafo.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Is your feature request related to a problem? Please describe.
The following code throws errors:

Under: my_module/
__init__.py

from .base import a, z
from .base_extended import b_p, d, e

base.py

def a(input: int) -> int:
    return input * 2

def z(input: int) -> int:
    return input * 3

base_extended.py

from hamilton.function_modifiers import parameterize, value

from my_module import base

b_p = parameterize(
    b={"input":value(1)},
    c={"input":value(2)} 
)(base.a) 

def d(b: int, c: int) -> int:
    return b + c

Then in my run.py outside my_module.

from hamilton import driver
import my_module
dr = driver.Builder().with_modules(my_module).build()
dr.display_all_functions("base_extended.png")
print(dr.execute(['b', 'c']))

Throws two possible things (if you allow module overrides one error goes away):

  1. b is redefined twice.
  2. a is missing from the graph.

Describe the likely problem

  1. I think we're modifying the underlying function in the parameterize decorator which results in a being lost.
  2. Because of (2) we have a effectively as a function twice. Once via the parameterize decorator, once via module import. This then means that we're defining b and c twice.

Describe the solution you'd like

  1. we should be able to import functions and use them in a decorator - without impacting the use of that function in hamilton as a standalone by itself thing.
  2. with (1) resolved I think things should then just work.

Describe alternatives you've considered
N/A

Additional context
Comes from a problem a user ran into in slack.

Lenguaje dominante
Jupyter Notebook
Estrellas
2.6k
Forks
228
Merge medio
8 d 9 min
PR fusionados (30 d)
27

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de apache/hamilton

Todos los issues de apache/hamilton

Issues similares

Más issues de Data Engineering

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.