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

more friendly error message in case no chunk manager is available #9676

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

keewis
Copy link
Collaborator

@keewis keewis commented Oct 24, 2024

The current error message when trying to use a chunked-array related method without actually having a chunk manager available is:

unrecognized chunk manager dask - must be one of: []

That's pretty confusing, so this catches the case where no chunk manager is available and raises an error with guidance on how to fix that.

  • Tests added
  • User visible changes (including notable bug fixes) are documented in whats-new.rst

@max-sixty
Copy link
Collaborator

Much better!

@mathause
Copy link
Collaborator

Thanks - I had a PR on this but don't mind closing mine in favor of this one. There is also #7963 which seems related.

@keewis
Copy link
Collaborator Author

keewis commented Oct 25, 2024

wow, I don't know how I missed two open PRs that aim to do something similar in different ways. Which one do we take?

If we merge this one your PR might still be valuable since it also changes the error message if there are chunk managers but not the one that was requested.

@dcherian
Copy link
Contributor

dcherian commented Nov 7, 2024

Shall we merge?

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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually not sure whether using dict is an improvement over lambda: {} in this case...

With the latter it is pretty clear that we have a function that returns an empty dict, while the former is more along the lines of "create a new dict", which as far as intent goes is not quite the same (the result is the same, though). Sure, maybe dict is a tiny bit faster, but we only call this once, while running the tests.

doc/whats-new.rst Outdated Show resolved Hide resolved
@TomNicholas TomNicholas added topic-error reporting topic-chunked-arrays Managing different chunked backends, e.g. dask labels Nov 8, 2024
@@ -95,6 +95,10 @@ def guess_chunkmanager(
"""

chunkmanagers = list_chunkmanagers()
if len(chunkmanagers) == 0:
raise ValueError(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely better, but perhaps it should throw a ModuleNotFoundError or ImportError?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would be kinda weird, though, because those usually need to point to a module that failed to import / was not found (and technically here we don't care about imports, we care about entrypoints).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's a bit odd, but ImportError doesn't actually require you to give a path to a specific module that it couldn't import (it's an optional argument), and I do think there would be value in the ImportError indicating to users that it's not really xarray's fault, it's their fault for not having set up an environment in which dask is importable.

But I think it's fine either way, and I agree it's not obvious if an entrypoint issue should raise an ImportError or not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we could actually just special case and state the name of the module that failed to be imported.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for ImportError. ImportError mentioning dask will do a better job of helping users figure out how to solve this themselves.

@TomNicholas
Copy link
Member

TomNicholas commented Nov 8, 2024

wow, I don't know how I missed two open PRs that aim to do something similar in different ways. Which one do we take?

Sorry for dropping the ball on reviewing / merging these guys 😞

Let's merge this one.

If we merge this one your PR might still be valuable since it also changes the error message if there are chunk managers but not the one that was requested.

This change would also be useful but is much less likely to come up.

Co-authored-by: Tom Nicholas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-chunked-arrays Managing different chunked backends, e.g. dask topic-error reporting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants