Skip to content

Engine is no longer inferred for filenames not ending in ".nc" #5295

Closed

Description

@shoyer

This works with xarray=0.17.0:

import xarray
xarray.Dataset({'x': [1, 2, 3]}).to_netcdf('tmp')
xarray.open_dataset('tmp')

On xarray 0.18.0, it fails:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-1-20e128a730aa> in <module>()
      2 
      3 xarray.Dataset({'x': [1, 2, 3]}).to_netcdf('tmp')
----> 4 xarray.open_dataset('tmp')

/usr/local/lib/python3.7/dist-packages/xarray/backends/api.py in open_dataset(filename_or_obj, engine, chunks, cache, decode_cf, mask_and_scale, decode_times, decode_timedelta, use_cftime, concat_characters, decode_coords, drop_variables, backend_kwargs, *args, **kwargs)
    483 
    484     if engine is None:
--> 485         engine = plugins.guess_engine(filename_or_obj)
    486 
    487     backend = plugins.get_backend(engine)

/usr/local/lib/python3.7/dist-packages/xarray/backends/plugins.py in guess_engine(store_spec)
    110             warnings.warn(f"{engine!r} fails while guessing", RuntimeWarning)
    111 
--> 112     raise ValueError("cannot guess the engine, try passing one explicitly")
    113 
    114 

ValueError: cannot guess the engine, try passing one explicitly

I'm not entirely sure what changed. My guess is that we used to fall-back to trying to use SciPy, but don't do that anymore. A potential fix would be reading strings as filenames in xarray.backends.utils.read_magic_number.

Related: #5291

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions