Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

friendlier error messages for missing chunk managers #9676

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 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
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Bug fixes
By `Stephan Hoyer <https://github.com/shoyer>`_.
- Fix regression in the interoperability of :py:meth:`DataArray.polyfit` and :py:meth:`xr.polyval` for date-time coordinates. (:pull:`9691`).
By `Pascal Bourgault <https://github.com/aulemahal>`_.
- Improve the error message raised when using chunked-array methods if no chunk manager is available (:pull:`9676`)
By `Justus Magin <https://github.com/keewis>`_.

Documentation
~~~~~~~~~~~~~
Expand Down Expand Up @@ -133,6 +135,7 @@ Bug fixes
- Fix issue where polyfit wouldn't handle non-dimension coordinates. (:issue:`4375`, :pull:`9369`)
By `Karl Krauth <https://github.com/Karl-Krauth>`_.


keewis marked this conversation as resolved.
Show resolved Hide resolved
Documentation
~~~~~~~~~~~~~

Expand Down
4 changes: 4 additions & 0 deletions xarray/namedarray/parallelcompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ def guess_chunkmanager(
"""

chunkmanagers = list_chunkmanagers()
if len(chunkmanagers) == 0:
raise ValueError(
dcherian marked this conversation as resolved.
Show resolved Hide resolved
dcherian marked this conversation as resolved.
Show resolved Hide resolved
"no chunk managers available. Try installing `dask` or a package that provides a chunk manager."
keewis marked this conversation as resolved.
Show resolved Hide resolved
)

if manager is None:
if len(chunkmanagers) == 1:
Expand Down
14 changes: 9 additions & 5 deletions xarray/tests/test_parallelcompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
list_chunkmanagers,
load_chunkmanagers,
)
from xarray.tests import has_dask, requires_dask
from xarray.tests import requires_dask


class DummyChunkedArray(np.ndarray):
Expand Down Expand Up @@ -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"):
dcherian marked this conversation as resolved.
Show resolved Hide resolved
guess_chunkmanager("foo")

Expand All @@ -167,9 +169,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", dict
dcherian marked this conversation as resolved.
Show resolved Hide resolved
)
with pytest.raises(ValueError, match="no chunk managers available"):
dcherian marked this conversation as resolved.
Show resolved Hide resolved
guess_chunkmanager("dask")

@requires_dask
Expand Down
Loading