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