diff --git a/xarray/namedarray/parallelcompat.py b/xarray/namedarray/parallelcompat.py index cd57a8d4487..b3e017c9cda 100644 --- a/xarray/namedarray/parallelcompat.py +++ b/xarray/namedarray/parallelcompat.py @@ -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)}") diff --git a/xarray/tests/test_parallelcompat.py b/xarray/tests/test_parallelcompat.py index e79e8a4c07d..4bb30649676 100644 --- a/xarray/tests/test_parallelcompat.py +++ b/xarray/tests/test_parallelcompat.py @@ -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)