Get namespace of chunk-handling methods, guessing from what's available. If the name of a specific ChunkManager is given (e.g. "dask"), then use that. Else use whatever is installed, defaulting to dask if there are multiple options.
(
manager: str | ChunkManagerEntrypoint[Any] | None,
)
| 92 | |
| 93 | |
| 94 | def guess_chunkmanager( |
| 95 | manager: str | ChunkManagerEntrypoint[Any] | None, |
| 96 | ) -> ChunkManagerEntrypoint[Any]: |
| 97 | """ |
| 98 | Get namespace of chunk-handling methods, guessing from what's available. |
| 99 | |
| 100 | If the name of a specific ChunkManager is given (e.g. "dask"), then use that. |
| 101 | Else use whatever is installed, defaulting to dask if there are multiple options. |
| 102 | """ |
| 103 | |
| 104 | available_chunkmanagers = list_chunkmanagers() |
| 105 | |
| 106 | if manager is None: |
| 107 | if len(available_chunkmanagers) == 1: |
| 108 | # use the only option available |
| 109 | manager = next(iter(available_chunkmanagers.keys())) |
| 110 | else: |
| 111 | # use the one in options (default dask) |
| 112 | manager = OPTIONS["chunk_manager"] |
| 113 | |
| 114 | if isinstance(manager, str): |
| 115 | if manager not in available_chunkmanagers and manager in KNOWN_CHUNKMANAGERS: |
| 116 | raise ImportError( |
| 117 | f"chunk manager {manager!r} is not available." |
| 118 | f" Please make sure {KNOWN_CHUNKMANAGERS[manager]!r} is installed" |
| 119 | " and importable." |
| 120 | ) |
| 121 | elif len(available_chunkmanagers) == 0: |
| 122 | raise ImportError( |
| 123 | "no chunk managers available. Try installing `dask` or another package" |
| 124 | " that provides a chunk manager." |
| 125 | ) |
| 126 | elif manager not in available_chunkmanagers: |
| 127 | raise ValueError( |
| 128 | f"unrecognized chunk manager {manager!r} - must be one of the installed" |
| 129 | f" chunk managers: {list(available_chunkmanagers)}" |
| 130 | ) |
| 131 | |
| 132 | return available_chunkmanagers[manager] |
| 133 | elif isinstance(manager, ChunkManagerEntrypoint): |
| 134 | # already a valid ChunkManager so just pass through |
| 135 | return manager |
| 136 | else: |
| 137 | raise TypeError( |
| 138 | "manager must be a string or instance of ChunkManagerEntrypoint," |
| 139 | f" but received type {type(manager)}" |
| 140 | ) |
| 141 | |
| 142 | |
| 143 | def get_chunked_array_type(*args: Any) -> ChunkManagerEntrypoint[Any]: |
searching dependent graphs…