MCPcopy Create free account
hub / github.com/dask/dask / _simplify_up

Method _simplify_up

dask/dataframe/dask_expr/_expr.py:2415–2460  ·  view source on GitHub ↗
(self, parent, dependents)

Source from the content-addressed store, hash-verified

2413 return (None,) * (self.frame.npartitions + 1)
2414
2415 def _simplify_up(self, parent, dependents):
2416 if isinstance(parent, Filter) and self._filter_passthrough_available(
2417 parent, dependents
2418 ):
2419 parents = [
2420 p().columns
2421 for p in dependents[self._name]
2422 if p() is not None and not isinstance(p(), Filter)
2423 ]
2424 predicate = None
2425 if not set(flatten(parents, list)).issubset(set(self.frame.columns)):
2426 # one of the filters is the Index
2427 name = self.operand("name") or self.frame._meta.index.name
2428 if name is no_default and self.frame._meta.index.name is None:
2429 name = "index"
2430 elif self.frame._meta.index.name is not None:
2431 name = self.frame._meta.index.name
2432 # replace the projection of the former index with the actual index
2433 subs = Projection(self, name)
2434 predicate = parent.predicate.substitute(subs, Index(self.frame))
2435 elif self.frame.ndim == 1 and not self.operand("drop"):
2436 name = self.frame._meta.name
2437 # Avoid Projection since we are already a Series
2438 subs = Projection(self, name)
2439 predicate = parent.predicate.substitute(subs, self.frame)
2440 return self._filter_simplification(parent, predicate)
2441
2442 if isinstance(parent, Projection):
2443 if self.frame.ndim == 1 and not self.drop:
2444 if isinstance(parent.operand("columns"), list):
2445 # Don't bother, dimensionality changes are tricky here and
2446 # potential improvement is tiny
2447 return
2448 col = parent.operand("columns")
2449 if col in (self.name, "index", self.frame._meta.index.name):
2450 return
2451 if all(
2452 isinstance(d(), Projection) and d().operand("columns") == col
2453 for d in dependents[self._name]
2454 ):
2455 return type(self)(self.frame, True, self.name)
2456 return
2457 result = plain_column_projection(self, parent, dependents)
2458 if result is not None and set(result.columns) != set(result.frame.columns):
2459 result = result.substitute_parameters({"drop": True})
2460 return result
2461
2462
2463class AddPrefixSeries(Elemwise):

Callers

nothing calls this directly

Calls 11

flattenFunction · 0.90
setClass · 0.85
ProjectionClass · 0.85
allFunction · 0.85
plain_column_projectionFunction · 0.85
operandMethod · 0.80
substitute_parametersMethod · 0.80
IndexClass · 0.70
substituteMethod · 0.45

Tested by

no test coverage detected