diff --git a/dask_expr/_core.py b/dask_expr/_core.py index afff3be16..afedefb8a 100644 --- a/dask_expr/_core.py +++ b/dask_expr/_core.py @@ -48,6 +48,7 @@ def __new__(cls, *args, **kwargs): return Expr._instances[_name] Expr._instances[_name] = inst + inst.simplified = False if inst._required_attribute: dep = next(iter(_dependencies))._meta if not hasattr(dep, inst._required_attribute): @@ -299,9 +300,12 @@ def simplify_once(self, dependents: defaultdict): expr: output expression """ + if self.simplified: + return self expr = self - + n = 0 while True: + n += 1 out = expr._simplify_down() if out is None: out = expr @@ -338,7 +342,7 @@ def simplify_once(self, dependents: defaultdict): expr = type(expr)(*new_operands) break - + expr.simplified = True return expr def simplify(self) -> Expr: @@ -349,6 +353,7 @@ def simplify(self) -> Expr: if new._name == expr._name: break expr = new + # print(f"Cache has size {len(_seen)=}") return expr def _simplify_down(self):