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

Improve error message for guess engine #5455

Merged
merged 15 commits into from
Jun 23, 2021
Merged

Improve error message for guess engine #5455

merged 15 commits into from
Jun 23, 2021

Conversation

aurghs
Copy link
Collaborator

@aurghs aurghs commented Jun 9, 2021

When open_dataset() fails because no working engines are found, it suggests installing the dependencies of the compatible internal backends, providing explicitly the list.

@aurghs aurghs requested review from alexamici and mathause June 9, 2021 15:22
Copy link
Collaborator

@mathause mathause left a comment

Choose a reason for hiding this comment

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

Looks good to me. I added some small suggestions.

@@ -146,6 +146,9 @@ def open_dataset(
)
return ds

@staticmethod
def are_dependencies_installed() -> bool:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe call this dependencies_installed, or is_installed, installed, or available?

Could be:

class CfgribfBackendEntrypoint(BackendEntrypoint):
    available = has_cfgrib

Copy link
Collaborator

Choose a reason for hiding this comment

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

I suggested not to use is_installed because the backend is obviously installed, are the dependencies that are missing.

I like available as a name.

I have a slight preference to keep it a method as it is more powerful, but you can use a properties in the case you need, so if other like it I'll not object to change it to an attribute.

Copy link
Collaborator Author

@aurghs aurghs Jun 10, 2021

Choose a reason for hiding this comment

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

available is fine for me and also using an attribute instead of a function

Comment on lines +134 to +135
"xarray is unable to open this file because it has no currently "
"installed IO backends. Xarray's read/write support requires "
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"xarray is unable to open this file because it has no currently "
"installed IO backends. Xarray's read/write support requires "
"xarray is unable to open this file because no IO backend "
"is currently installed. Xarray's read/write support requires "

"http://xarray.pydata.org/en/stable/user-guide/io.html"
error_msg = (
"found the following matches with the input file in xarray's IO "
f"backends: {compatible}. But their dependencies may not be installed, see:\n"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
f"backends: {compatible}. But their dependencies may not be installed, see:\n"
f"backends: {compatible}. But they may not be installed, see:\n"

?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This in not technically correct. You may have rioxarray installed that provides the engine, but not GDAL so you get the error. I would suggest to keep the message like it is.

return engine
except Exception:
warnings.warn(f"{engine!r} fails while guessing", RuntimeWarning)

compatible = []
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
compatible = []
# no engine found, find out why
compatible_engines = []

Comment on lines 84 to 87
backend_entrypoints = {}
for backend_name, backend in BACKEND_ENTRYPOINTS.items():
if backend.are_dependencies_installed():
backend_entrypoints[backend_name] = backend
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
backend_entrypoints = {}
for backend_name, backend in BACKEND_ENTRYPOINTS.items():
if backend.are_dependencies_installed():
backend_entrypoints[backend_name] = backend
backend_entrypoints = {
backend_name: backend
for backend_name, backend in BACKEND_ENTRYPOINTS.items()
if backend.are_dependencies_installed()
}

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 prefer avoiding comprehension if they are complex since they are less readable.

Copy link
Contributor

Choose a reason for hiding this comment

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

In this blackened format I think it's as readable as the normal loop. But I don't feel that strongly about this, if you prefer the other one that's fine too.

Copy link
Collaborator

@mathause mathause left a comment

Choose a reason for hiding this comment

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

I still prefer my open suggestion but let's not get hung up over this. I'll merge soon (or you can).

@mathause mathause merged commit eea7673 into pydata:master Jun 23, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Jun 23, 2021

Unit Test Results

0 files  0 suites   0s ⏱️
0 tests 0 ✔️ 0 💤 0 ❌

Results for commit eea7673.

♻️ This comment has been updated with latest results.

dcherian added a commit to dcherian/xarray that referenced this pull request Jun 23, 2021
* main:
  Improve error message for guess engine (pydata#5455)
  Refactor dataset groupby tests (pydata#5506)
  DOC: zarr note on encoding (pydata#5427)
  Allow plotting categorical data (pydata#5464)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suggesting specific IO backends to install when open_dataset() fails
4 participants