-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Changes from 14 commits
d7e3be9
79d8237
9f67bc3
e3180ba
e528603
e1c5a5e
f2abf6b
733a7dd
be8ead7
3e028ab
f32ace9
682ce0e
defe2b6
36a18df
f640ff6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -81,7 +81,10 @@ def sort_backends(backend_entrypoints): | |||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
def build_engines(pkg_entrypoints): | ||||||||||||||||||||
backend_entrypoints = BACKEND_ENTRYPOINTS.copy() | ||||||||||||||||||||
backend_entrypoints = {} | ||||||||||||||||||||
for backend_name, backend in BACKEND_ENTRYPOINTS.items(): | ||||||||||||||||||||
if backend.are_dependencies_installed(): | ||||||||||||||||||||
backend_entrypoints[backend_name] = backend | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||||||||||||||||
pkg_entrypoints = remove_duplicates(pkg_entrypoints) | ||||||||||||||||||||
external_backend_entrypoints = backends_dict_from_pkg(pkg_entrypoints) | ||||||||||||||||||||
backend_entrypoints.update(external_backend_entrypoints) | ||||||||||||||||||||
|
@@ -101,30 +104,49 @@ def guess_engine(store_spec): | |||||||||||||||||||
|
||||||||||||||||||||
for engine, backend in engines.items(): | ||||||||||||||||||||
try: | ||||||||||||||||||||
if backend.guess_can_open and backend.guess_can_open(store_spec): | ||||||||||||||||||||
if backend.guess_can_open(store_spec): | ||||||||||||||||||||
return engine | ||||||||||||||||||||
except Exception: | ||||||||||||||||||||
warnings.warn(f"{engine!r} fails while guessing", RuntimeWarning) | ||||||||||||||||||||
|
||||||||||||||||||||
compatible = [] | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
for engine, backend_cls in BACKEND_ENTRYPOINTS.items(): | ||||||||||||||||||||
try: | ||||||||||||||||||||
backend = backend_cls() | ||||||||||||||||||||
if backend.guess_can_open(store_spec): | ||||||||||||||||||||
compatible.append(engine) | ||||||||||||||||||||
except Exception: | ||||||||||||||||||||
warnings.warn(f"{engine!r} fails while guessing", RuntimeWarning) | ||||||||||||||||||||
|
||||||||||||||||||||
installed = [k for k in engines if k != "store"] | ||||||||||||||||||||
if installed: | ||||||||||||||||||||
raise ValueError( | ||||||||||||||||||||
"did not find a match in any of xarray's currently installed IO " | ||||||||||||||||||||
f"backends {installed}. Consider explicitly selecting one of the " | ||||||||||||||||||||
"installed backends via the ``engine`` parameter to " | ||||||||||||||||||||
"xarray.open_dataset(), or installing additional IO dependencies:\n" | ||||||||||||||||||||
"http://xarray.pydata.org/en/stable/getting-started-guide/installing.html\n" | ||||||||||||||||||||
"http://xarray.pydata.org/en/stable/user-guide/io.html" | ||||||||||||||||||||
) | ||||||||||||||||||||
if not compatible: | ||||||||||||||||||||
if installed: | ||||||||||||||||||||
error_msg = ( | ||||||||||||||||||||
"did not find a match in any of xarray's currently installed IO " | ||||||||||||||||||||
f"backends {installed}. Consider explicitly selecting one of the " | ||||||||||||||||||||
"installed engines via the ``engine`` parameter, or installing " | ||||||||||||||||||||
"additional IO dependencies, see:\n" | ||||||||||||||||||||
"http://xarray.pydata.org/en/stable/getting-started-guide/installing.html\n" | ||||||||||||||||||||
"http://xarray.pydata.org/en/stable/user-guide/io.html" | ||||||||||||||||||||
) | ||||||||||||||||||||
else: | ||||||||||||||||||||
error_msg = ( | ||||||||||||||||||||
"xarray is unable to open this file because it has no currently " | ||||||||||||||||||||
"installed IO backends. Xarray's read/write support requires " | ||||||||||||||||||||
Comment on lines
+134
to
+135
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
"installing optional IO dependencies, see:\n" | ||||||||||||||||||||
"http://xarray.pydata.org/en/stable/getting-started-guide/installing.html\n" | ||||||||||||||||||||
"http://xarray.pydata.org/en/stable/user-guide/io" | ||||||||||||||||||||
) | ||||||||||||||||||||
else: | ||||||||||||||||||||
raise ValueError( | ||||||||||||||||||||
"xarray is unable to open this file because it has no currently " | ||||||||||||||||||||
"installed IO backends. Xarray's read/write support requires " | ||||||||||||||||||||
"installing optional dependencies:\n" | ||||||||||||||||||||
"http://xarray.pydata.org/en/stable/getting-started-guide/installing.html\n" | ||||||||||||||||||||
"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" | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This in not technically correct. You may have |
||||||||||||||||||||
"http://xarray.pydata.org/en/stable/user-guide/io.html \n" | ||||||||||||||||||||
"http://xarray.pydata.org/en/stable/getting-started-guide/installing.html" | ||||||||||||||||||||
) | ||||||||||||||||||||
|
||||||||||||||||||||
raise ValueError(error_msg) | ||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
def get_backend(engine): | ||||||||||||||||||||
"""Select open_dataset method based on current engine.""" | ||||||||||||||||||||
|
There was a problem hiding this comment.
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
, oris_installed
,installed
, oravailable
?Could be:
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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