From 1396ec7f78c663da50a647b7e3ad70702cc46570 Mon Sep 17 00:00:00 2001 From: Alessandro Amici Date: Thu, 7 Jan 2021 15:02:02 +0100 Subject: [PATCH 1/2] Remove special case in guess_engines --- xarray/backends/plugins.py | 5 ----- xarray/tests/test_backends.py | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/xarray/backends/plugins.py b/xarray/backends/plugins.py index 6e9045c1c7f..d5799a78f91 100644 --- a/xarray/backends/plugins.py +++ b/xarray/backends/plugins.py @@ -104,11 +104,6 @@ def list_engines(): def guess_engine(store_spec): engines = list_engines() - # use the pre-defined selection order for netCDF files - for engine in ["netcdf4", "h5netcdf", "scipy"]: - if engine in engines and engines[engine].guess_can_open(store_spec): - return engine - for engine, backend in engines.items(): try: if backend.guess_can_open and backend.guess_can_open(store_spec): diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index 2d20f7f63b3..3750c0715ae 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -2661,7 +2661,7 @@ def test_open_fileobj(self): open_dataset(f, engine="scipy") f.seek(8) - with raises_regex(ValueError, "read/write pointer not at the start"): + with raises_regex(ValueError, "cannot guess the engine"): open_dataset(f) From e9f2a40d048dac9cf02d346a4c824d692b04c707 Mon Sep 17 00:00:00 2001 From: Alessandro Amici Date: Thu, 7 Jan 2021 15:15:32 +0100 Subject: [PATCH 2/2] Sync the error messages between APIv1 and APIv2 --- xarray/core/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/xarray/core/utils.py b/xarray/core/utils.py index c0e2635d084..fc956c75ca3 100644 --- a/xarray/core/utils.py +++ b/xarray/core/utils.py @@ -640,6 +640,7 @@ def read_magic_number(filename_or_obj, count=8): elif isinstance(filename_or_obj, io.IOBase): if filename_or_obj.tell() != 0: raise ValueError( + "cannot guess the engine, " "file-like object read/write pointer not at the start of the file, " "please close and reopen, or use a context manager" )