Infer the collection names from the dask keys, under the assumption that all keys are either tuples with matching first element, and that element is a string, or there is exactly one key and it is a string. Examples -------- >>> a.__dask_keys__() # doctest: +SKIP ["foo", "b
(collection)
| 1210 | |
| 1211 | |
| 1212 | def get_collection_names(collection) -> set[str]: |
| 1213 | """Infer the collection names from the dask keys, under the assumption that all keys |
| 1214 | are either tuples with matching first element, and that element is a string, or |
| 1215 | there is exactly one key and it is a string. |
| 1216 | |
| 1217 | Examples |
| 1218 | -------- |
| 1219 | >>> a.__dask_keys__() # doctest: +SKIP |
| 1220 | ["foo", "bar"] |
| 1221 | >>> get_collection_names(a) # doctest: +SKIP |
| 1222 | {"foo", "bar"} |
| 1223 | >>> b.__dask_keys__() # doctest: +SKIP |
| 1224 | [[("foo-123", 0, 0), ("foo-123", 0, 1)], [("foo-123", 1, 0), ("foo-123", 1, 1)]] |
| 1225 | >>> get_collection_names(b) # doctest: +SKIP |
| 1226 | {"foo-123"} |
| 1227 | """ |
| 1228 | if not is_dask_collection(collection): |
| 1229 | raise TypeError(f"Expected Dask collection; got {type(collection)}") |
| 1230 | return {get_name_from_key(k) for k in flatten(collection.__dask_keys__())} |
| 1231 | |
| 1232 | |
| 1233 | def get_name_from_key(key: Key) -> str: |
searching dependent graphs…