Skip to content

Commit cae4df1

Browse files
committed
Ensure rewrite methods always exist
1 parent 9c4bdf1 commit cae4df1

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

Diff for: dask_expr/_core.py

+27-17
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ def __new__(cls, *args, **kwargs):
5656
raise ValueError(f"{dep} has no attribute {inst._required_attribute}")
5757
return inst
5858

59+
def _tune_down(self):
60+
return None
61+
62+
def _tune_up(self, parent):
63+
return None
64+
65+
def _cull_down(self):
66+
return None
67+
68+
def _cull_up(self, parent):
69+
return None
70+
5971
@property
6072
def _required_attribute(self) -> str:
6173
# Specify if the first `dependency` must support
@@ -226,28 +238,26 @@ def rewrite(self, kind: str):
226238
_continue = False
227239

228240
# Rewrite this node
229-
if down_name in expr.__dir__():
230-
out = getattr(expr, down_name)()
241+
out = getattr(expr, down_name)()
242+
if out is None:
243+
out = expr
244+
if not isinstance(out, Expr):
245+
return out
246+
if out._name != expr._name:
247+
expr = out
248+
continue
249+
250+
# Allow children to rewrite their parents
251+
for child in expr.dependencies():
252+
out = getattr(child, up_name)(expr)
231253
if out is None:
232254
out = expr
233255
if not isinstance(out, Expr):
234256
return out
235-
if out._name != expr._name:
257+
if out is not expr and out._name != expr._name:
236258
expr = out
237-
continue
238-
239-
# Allow children to rewrite their parents
240-
for child in expr.dependencies():
241-
if up_name in child.__dir__():
242-
out = getattr(child, up_name)(expr)
243-
if out is None:
244-
out = expr
245-
if not isinstance(out, Expr):
246-
return out
247-
if out is not expr and out._name != expr._name:
248-
expr = out
249-
_continue = True
250-
break
259+
_continue = True
260+
break
251261

252262
if _continue:
253263
continue

0 commit comments

Comments
 (0)