Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions xarray/namedarray/parallelcompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,15 @@ def get_chunked_array_type(*args: Any) -> ChunkManagerEntrypoint[Any]:
if chunkmanager.is_chunked_array(chunked_arr)
]
if not selected:
if (
maybe_lib := type(chunked_arr).__module__.split(".")[0]
) in KNOWN_CHUNKMANAGERS:
suggestion = f"Please try installing {KNOWN_CHUNKMANAGERS[maybe_lib]!r}."
else:
suggestion = "This is usually the result of a missing dependency."
raise TypeError(
f"Could not find a Chunk Manager which recognises type {type(chunked_arr)}"
f" {suggestion}"
)
elif len(selected) >= 2:
raise TypeError(f"Multiple ChunkManagers recognise type {type(chunked_arr)}")
Expand Down
14 changes: 13 additions & 1 deletion xarray/tests/test_parallelcompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,19 @@ def test_raise_if_no_matching_chunkmanagers(self) -> None:
dummy_arr = DummyChunkedArray([1, 2, 3])

with pytest.raises(
TypeError, match="Could not find a Chunk Manager which recognises"
TypeError,
match=r"Could not find a Chunk Manager .* missing dependency.",
):
get_chunked_array_type(dummy_arr)

def test_recommend_known_chunkmanager_if_unavailable(self, monkeypatch) -> None:
# For instance for a cubed array, this recommends installing cubed-xarray
monkeypatch.setitem(KNOWN_CHUNKMANAGERS, "xarray", "dummy")

dummy_arr = DummyChunkedArray([1, 2, 3])
with pytest.raises(
TypeError,
match=r"Could not find a Chunk Manager .* try installing 'dummy'.",
):
get_chunked_array_type(dummy_arr)

Expand Down
Loading