Skip to content

Commit

Permalink
Ensure rewrite methods always exist
Browse files Browse the repository at this point in the history
  • Loading branch information
fjetter committed Jan 23, 2024
1 parent 9c4bdf1 commit cae4df1
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions dask_expr/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ def __new__(cls, *args, **kwargs):
raise ValueError(f"{dep} has no attribute {inst._required_attribute}")
return inst

def _tune_down(self):
return None

def _tune_up(self, parent):
return None

def _cull_down(self):
return None

def _cull_up(self, parent):
return None

@property
def _required_attribute(self) -> str:
# Specify if the first `dependency` must support
Expand Down Expand Up @@ -226,28 +238,26 @@ def rewrite(self, kind: str):
_continue = False

# Rewrite this node
if down_name in expr.__dir__():
out = getattr(expr, down_name)()
out = getattr(expr, down_name)()
if out is None:
out = expr
if not isinstance(out, Expr):
return out
if out._name != expr._name:
expr = out
continue

# Allow children to rewrite their parents
for child in expr.dependencies():
out = getattr(child, up_name)(expr)
if out is None:
out = expr
if not isinstance(out, Expr):
return out
if out._name != expr._name:
if out is not expr and out._name != expr._name:
expr = out
continue

# Allow children to rewrite their parents
for child in expr.dependencies():
if up_name in child.__dir__():
out = getattr(child, up_name)(expr)
if out is None:
out = expr
if not isinstance(out, Expr):
return out
if out is not expr and out._name != expr._name:
expr = out
_continue = True
break
_continue = True
break

if _continue:
continue
Expand Down

0 comments on commit cae4df1

Please sign in to comment.