Skip to content

ValueError cannot guess the engine, try passing one explicitly with xarray 0.18 #1263

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

Closed
weiji14 opened this issue May 7, 2021 · 0 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists
Milestone

Comments

@weiji14
Copy link
Member

weiji14 commented May 7, 2021

Description of the problem

xarray v0.18 released on 6 May 2021 (see changelog at https://xarray.pydata.org/en/v0.18.0/whats-new.html) resulted in some API changes and this is breaking PyGMT tests that are trying to read from a *.grd file. Specifically the earth relief grids from the pygmt.datasets.load_earth_relief function don't work, and I think it also segfaults on Windows so it is a major issue.

For users: Temporary solution would be to downgrade to xarray v0.17.0 if you want to continue using the load_earth_relief function.

For PyGMT developers, we probably need to explicitly set an 'engine' in the xarray.open_dataarray() calls we make. Or we could post an upstream issue to xarray to handle *.grd files natively. Thoughts?

Full code that generated the error

PASTE CODE HERE

Full error message

https://github.com/GenericMappingTools/pygmt/runs/2523330164?check_suite_focus=true#step:11:1994

=================================== FAILURES ===================================
________________ [doctest] pygmt.accessors.GMTDataArrayAccessor ________________
011 
012     This is the GMT extension for :class:`xarray.DataArray`.
013 
014     You can access various GMT specific metadata about your grid as follows:
015 
016     >>> from pygmt.datasets import load_earth_relief
017     >>> # Use the global Earth relief grid with 1 degree spacing
018     >>> grid = load_earth_relief(resolution="01d")
UNEXPECTED EXCEPTION: ValueError('cannot guess the engine, try passing one explicitly')
Traceback (most recent call last):
  File "/usr/share/miniconda3/envs/pygmt/lib/python3.7/doctest.py", line 1337, in __run
    compileflags, 1), test.globs)
  File "<doctest pygmt.accessors.GMTDataArrayAccessor[1]>", line 1, in <module>
  File "/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/pygmt/helpers/decorators.py", line 438, in new_module
    return module_func(*args, **kwargs)
  File "/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/pygmt/datasets/earth_relief.py", line 136, in load_earth_relief
    with xr.open_dataarray(fname) as dataarray:
  File "/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/xarray/backends/api.py", line 673, in open_dataarray
    **kwargs,
  File "/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/xarray/backends/api.py", line 485, in open_dataset
    engine = plugins.guess_engine(filename_or_obj)
  File "/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/xarray/backends/plugins.py", line 112, in guess_engine
    raise ValueError("cannot guess the engine, try passing one explicitly")
ValueError: cannot guess the engine, try passing one explicitly
/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/pygmt/accessors.py:18: UnexpectedException
_____________ [doctest] pygmt.clib.conversion.dataarray_to_matrix ______________
040     ------
041     GMTInvalidInput
042         If the grid has more than two dimensions or variable grid spacing.
043 
044     Examples
045     --------
046 
047     >>> from pygmt.datasets import load_earth_relief
048     >>> # Use the global Earth relief grid with 1 degree spacing
049     >>> grid = load_earth_relief(resolution="01d")
UNEXPECTED EXCEPTION: ValueError('cannot guess the engine, try passing one explicitly')
Traceback (most recent call last):
  File "/usr/share/miniconda3/envs/pygmt/lib/python3.7/doctest.py", line 1337, in __run
    compileflags, 1), test.globs)
  File "<doctest pygmt.clib.conversion.dataarray_to_matrix[1]>", line 1, in <module>
  File "/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/pygmt/helpers/decorators.py", line 438, in new_module
    return module_func(*args, **kwargs)
  File "/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/pygmt/datasets/earth_relief.py", line 136, in load_earth_relief
    with xr.open_dataarray(fname) as dataarray:
  File "/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/xarray/backends/api.py", line 673, in open_dataarray
    **kwargs,
  File "/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/xarray/backends/api.py", line 485, in open_dataset
    engine = plugins.guess_engine(filename_or_obj)
  File "/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/xarray/backends/plugins.py", line 112, in guess_engine
    raise ValueError("cannot guess the engine, try passing one explicitly")
ValueError: cannot guess the engine, try passing one explicitly
/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/pygmt/clib/conversion.py:49: UnexpectedException
_____________________ [doctest] pygmt.clib.session.Session _____________________
095         If you try to call a method outside of a 'with' block.
096     GMTVersionError
097         If the minimum required version of GMT is not found.
098 
099     Examples
100     --------
101 
102     >>> from pygmt.datasets import load_earth_relief
103     >>> from pygmt.helpers import GMTTempFile
104     >>> grid = load_earth_relief()
UNEXPECTED EXCEPTION: ValueError('cannot guess the engine, try passing one explicitly')
Traceback (most recent call last):
  File "/usr/share/miniconda3/envs/pygmt/lib/python3.7/doctest.py", line 1337, in __run
    compileflags, 1), test.globs)
  File "<doctest pygmt.clib.session.Session[2]>", line 1, in <module>
  File "/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/pygmt/helpers/decorators.py", line 438, in new_module
    return module_func(*args, **kwargs)
  File "/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/pygmt/datasets/earth_relief.py", line 136, in load_earth_relief
    with xr.open_dataarray(fname) as dataarray:
  File "/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/xarray/backends/api.py", line 673, in open_dataarray
    **kwargs,
  File "/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/xarray/backends/api.py", line 485, in open_dataset
    engine = plugins.guess_engine(filename_or_obj)
  File "/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/xarray/backends/plugins.py", line 112, in guess_engine
    raise ValueError("cannot guess the engine, try passing one explicitly")
ValueError: cannot guess the engine, try passing one explicitly
/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/pygmt/clib/session.py:104: UnexpectedException
__________ [doctest] pygmt.clib.session.Session.virtualfile_from_grid __________
277         fname : str
278             The name of virtual file. Pass this as a file name argument to a
279             GMT module.
280 
281         Examples
282         --------
283 
284         >>> from pygmt.datasets import load_earth_relief
285         >>> from pygmt.helpers import GMTTempFile
286         >>> data = load_earth_relief(resolution="01d")
UNEXPECTED EXCEPTION: ValueError('cannot guess the engine, try passing one explicitly')
Traceback (most recent call last):
  File "/usr/share/miniconda3/envs/pygmt/lib/python3.7/doctest.py", line 1337, in __run
    compileflags, 1), test.globs)
  File "<doctest pygmt.clib.session.Session.virtualfile_from_grid[2]>", line 1, in <module>
  File "/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/pygmt/helpers/decorators.py", line 438, in new_module
    return module_func(*args, **kwargs)
  File "/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/pygmt/datasets/earth_relief.py", line 136, in load_earth_relief
    with xr.open_dataarray(fname) as dataarray:
  File "/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/xarray/backends/api.py", line 673, in open_dataarray
    **kwargs,
  File "/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/xarray/backends/api.py", line 485, in open_dataset
    engine = plugins.guess_engine(filename_or_obj)
  File "/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/xarray/backends/plugins.py", line 112, in guess_engine
    **kwargs,
/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/xarray/backends/api.py:485: in open_dataset
    engine = plugins.guess_engine(filename_or_obj)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

store_spec = '/home/runner/.gmt/server/earth/earth_relief/earth_relief_30m_g.grd'

    def guess_engine(store_spec):
        engines = list_engines()
    
        for engine, backend in engines.items():
            try:
                if backend.guess_can_open and backend.guess_can_open(store_spec):
                    return engine
            except Exception:
                warnings.warn(f"{engine!r} fails while guessing", RuntimeWarning)
    
>       raise ValueError("cannot guess the engine, try passing one explicitly")
E       ValueError: cannot guess the engine, try passing one explicitly

/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/xarray/backends/plugins.py:112: ValueError
_________________________________ test_grdinfo _________________________________

    def test_grdinfo():
        """
        Make sure grdinfo works as expected.
        """
>       grid = load_earth_relief(registration="gridline")

/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/pygmt/tests/test_grdinfo.py:15: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/pygmt/helpers/decorators.py:438: in new_module
    return module_func(*args, **kwargs)
/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/pygmt/datasets/earth_relief.py:136: in load_earth_relief
    with xr.open_dataarray(fname) as dataarray:
/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/xarray/backends/api.py:673: in open_dataarray
    **kwargs,
/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/xarray/backends/api.py:485: in open_dataset
    engine = plugins.guess_engine(filename_or_obj)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

store_spec = '/home/runner/.gmt/server/earth/earth_relief/earth_relief_01d_g.grd'

    def guess_engine(store_spec):
        engines = list_engines()
    
        for engine, backend in engines.items():
            try:
                if backend.guess_can_open and backend.guess_can_open(store_spec):
                    return engine
            except Exception:
                warnings.warn(f"{engine!r} fails while guessing", RuntimeWarning)
    
>       raise ValueError("cannot guess the engine, try passing one explicitly")
E       ValueError: cannot guess the engine, try passing one explicitly

/usr/share/miniconda3/envs/pygmt/lib/python3.7/site-packages/xarray/backends/plugins.py:112: ValueError

System information

Please paste the output of python -c "import pygmt; pygmt.show_versions()":

PyGMT information:
  version: v0.3.2.dev131+gb51e3c2
System information:
  python: 3.9.2 | packaged by conda-forge | (default, Feb 21 2021, 05:02:46)  [GCC 9.3.0]
  executable: /usr/share/miniconda3/envs/pygmt/bin/python
  machine: Linux-5.4.0-1046-azure-x86_64-with-glibc2.31
Dependency information:
  numpy: 1.20.2
  pandas: 1.2.4
  xarray: 0.18.0
  netCDF4: 1.5.6
  packaging: 20.9
  ghostscript: 9.53.3
  gmt: 6.2.0rc1
GMT library information:
  binary dir: /usr/share/miniconda3/envs/pygmt/bin
  cores: 2
  grid layout: rows
  library path: /usr/share/miniconda3/envs/pygmt/lib/libgmt.so
  padding: 2
  plugin dir: /usr/share/miniconda3/envs/pygmt/lib/gmt/plugins
  share dir: /usr/share/miniconda3/envs/pygmt/share/gmt
  version: 6.2.0rc1
@weiji14 weiji14 added the bug Something isn't working label May 7, 2021
@weiji14 weiji14 added this to the 0.4.0 milestone May 7, 2021
@weiji14 weiji14 added the duplicate This issue or pull request already exists label May 7, 2021
@weiji14 weiji14 closed this as completed May 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

1 participant