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)
| 1329 | |
| 1330 | |
| 1331 | def get_collection_names(collection) -> set[str]: |
| 1332 | """Infer the collection names from the dask keys, under the assumption that all keys |
| 1333 | are either tuples with matching first element, and that element is a string, or |
| 1334 | there is exactly one key and it is a string. |
| 1335 | |
| 1336 | Examples |
| 1337 | -------- |
| 1338 | >>> a.__dask_keys__() # doctest: +SKIP |
| 1339 | ["foo", "bar"] |
| 1340 | >>> get_collection_names(a) # doctest: +SKIP |
| 1341 | {"foo", "bar"} |
| 1342 | >>> b.__dask_keys__() # doctest: +SKIP |
| 1343 | [[("foo-123", 0, 0), ("foo-123", 0, 1)], [("foo-123", 1, 0), ("foo-123", 1, 1)]] |
| 1344 | >>> get_collection_names(b) # doctest: +SKIP |
| 1345 | {"foo-123"} |
| 1346 | """ |
| 1347 | if not is_dask_collection(collection): |
| 1348 | raise TypeError(f"Expected Dask collection; got {type(collection)}") |
| 1349 | return {get_name_from_key(k) for k in flatten(collection.__dask_keys__())} |
| 1350 | |
| 1351 | |
| 1352 | def get_name_from_key(key: Key) -> str: |