A sequence of expressions This is used to be able to optimize multiple collections combined, e.g. when being computed simultaneously with ``dask.compute((Expr1, Expr2))``.
| 1192 | |
| 1193 | |
| 1194 | class _ExprSequence(Expr): |
| 1195 | """A sequence of expressions |
| 1196 | |
| 1197 | This is used to be able to optimize multiple collections combined, e.g. when |
| 1198 | being computed simultaneously with ``dask.compute((Expr1, Expr2))``. |
| 1199 | """ |
| 1200 | |
| 1201 | def __getitem__(self, other): |
| 1202 | return self.operands[other] |
| 1203 | |
| 1204 | def _layer(self) -> dict: |
| 1205 | return toolz.merge(op._layer() for op in self.operands) |
| 1206 | |
| 1207 | def __dask_keys__(self) -> list: |
| 1208 | all_keys = [] |
| 1209 | for op in self.operands: |
| 1210 | all_keys.append(list(op.__dask_keys__())) |
| 1211 | return all_keys |
| 1212 | |
| 1213 | def __repr__(self): |
| 1214 | return "ExprSequence(" + ", ".join(map(repr, self.operands)) + ")" |
| 1215 | |
| 1216 | __str__ = __repr__ |
| 1217 | |
| 1218 | def finalize_compute(self): |
| 1219 | return _ExprSequence( |
| 1220 | *(op.finalize_compute() for op in self.operands), |
| 1221 | ) |
| 1222 | |
| 1223 | def __dask_annotations__(self): |
| 1224 | annotations_by_type = {} |
| 1225 | for op in self.operands: |
| 1226 | for k, v in op.__dask_annotations__().items(): |
| 1227 | annotations_by_type.setdefault(k, {}).update(v) |
| 1228 | return annotations_by_type |
| 1229 | |
| 1230 | def __len__(self): |
| 1231 | return len(self.operands) |
| 1232 | |
| 1233 | def __iter__(self): |
| 1234 | return iter(self.operands) |
| 1235 | |
| 1236 | def _simplify_down(self): |
| 1237 | from dask.highlevelgraph import HighLevelGraph |
| 1238 | |
| 1239 | issue_warning = False |
| 1240 | hlgs = [] |
| 1241 | for op in self.operands: |
| 1242 | if isinstance(op, (HLGExpr, HLGFinalizeCompute)): |
| 1243 | hlgs.append(op) |
| 1244 | elif isinstance(op, dict): |
| 1245 | hlgs.append( |
| 1246 | HLGExpr( |
| 1247 | dsk=HighLevelGraph.from_collections( |
| 1248 | str(id(op)), op, dependencies=() |
| 1249 | ) |
| 1250 | ) |
| 1251 | ) |
no outgoing calls