From 1f71daced8f96e4cafccacb802dde1ccb7cdb48a Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Wed, 7 Aug 2024 15:45:03 +0200 Subject: [PATCH 1/4] raise an error message while guessing if there's no chunkmanager available --- xarray/namedarray/parallelcompat.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xarray/namedarray/parallelcompat.py b/xarray/namedarray/parallelcompat.py index dd555fe200a..ac2fa6465dd 100644 --- a/xarray/namedarray/parallelcompat.py +++ b/xarray/namedarray/parallelcompat.py @@ -103,6 +103,10 @@ def guess_chunkmanager( """ chunkmanagers = list_chunkmanagers() + if len(chunkmanagers) == 0: + raise ValueError( + "no chunk managers available. Try installing `dask` or a package that provides a chunk manager." + ) if manager is None: if len(chunkmanagers) == 1: From 66ed78cb5af2b9b73f474077b85f369691a14635 Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Thu, 24 Oct 2024 23:12:14 +0200 Subject: [PATCH 2/4] don't skip the no chunkmanager test if dask is not installed --- xarray/tests/test_parallelcompat.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/xarray/tests/test_parallelcompat.py b/xarray/tests/test_parallelcompat.py index dbe40be710c..2c7b9374eb9 100644 --- a/xarray/tests/test_parallelcompat.py +++ b/xarray/tests/test_parallelcompat.py @@ -16,7 +16,7 @@ list_chunkmanagers, load_chunkmanagers, ) -from xarray.tests import has_dask, requires_dask +from xarray.tests import requires_dask class DummyChunkedArray(np.ndarray): @@ -161,9 +161,11 @@ def test_get_dask_if_installed(self) -> None: chunkmanager = guess_chunkmanager(None) assert isinstance(chunkmanager, DaskManager) - @pytest.mark.skipif(has_dask, reason="requires dask not to be installed") - def test_dont_get_dask_if_not_installed(self) -> None: - with pytest.raises(ValueError, match="unrecognized chunk manager dask"): + def test_no_chunk_manager_available(self, monkeypatch) -> None: + monkeypatch.setattr( + "xarray.namedarray.parallelcompat.list_chunkmanagers", lambda: {} + ) + with pytest.raises(ValueError, match="no chunk managers available"): guess_chunkmanager("dask") @requires_dask From 04d605cbbb68aa392b13afed06b4591e308d6408 Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Thu, 24 Oct 2024 23:19:59 +0200 Subject: [PATCH 3/4] whats-new --- doc/whats-new.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index c3dd6776c27..ec3ca36ef56 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -76,6 +76,8 @@ Bug fixes `_. - Fix binning by multiple variables where some bins have no observations. (:issue:`9630`). By `Deepak Cherian `_. +- Improve the error message raised when using chunked-array methods if no chunk manager is available (:pull:`9676`) + By `Justus Magin `_. Documentation ~~~~~~~~~~~~~ From b1d40179b075c0bac97375e7b03f0db27a8f27ad Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Thu, 24 Oct 2024 23:30:12 +0200 Subject: [PATCH 4/4] ensure at least one chunk manager is available --- xarray/tests/test_parallelcompat.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xarray/tests/test_parallelcompat.py b/xarray/tests/test_parallelcompat.py index 517d9fc342c..5cf62e5a317 100644 --- a/xarray/tests/test_parallelcompat.py +++ b/xarray/tests/test_parallelcompat.py @@ -158,7 +158,9 @@ def test_get_chunkmanger_via_set_options(self, register_dummy_chunkmanager) -> N chunkmanager = guess_chunkmanager(None) assert isinstance(chunkmanager, DummyChunkManager) - def test_fail_on_nonexistent_chunkmanager(self) -> None: + def test_fail_on_nonexistent_chunkmanager( + self, register_dummy_chunkmanager + ) -> None: with pytest.raises(ValueError, match="unrecognized chunk manager foo"): guess_chunkmanager("foo")