From dc03b8009f4cdc55d52c2d73f8f17b809395ed66 Mon Sep 17 00:00:00 2001 From: Kai Germaschewski Date: Wed, 1 Jan 2025 07:47:17 -0500 Subject: [PATCH] fix warning from scipy backend guess_can_open on directory (#9911) When passing a directory to open_dataset(), the scipy backend fails and a "RuntimeWarning: 'scipy' fails while guessing" is produced. This affects me since I'm implementing a backend to read data written by the adios2 package, whose data "files" are actually a directory. This tiny patch treats this case just like file not found, that is, the scipy backend will now return that it cannot open such a "file", but without raising an exception. --- xarray/core/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/core/utils.py b/xarray/core/utils.py index 2b992f0249b..11f9ee49ca2 100644 --- a/xarray/core/utils.py +++ b/xarray/core/utils.py @@ -645,7 +645,7 @@ def try_read_magic_number_from_path(pathlike, count=8) -> bytes | None: try: with open(path, "rb") as f: return read_magic_number_from_file(f, count) - except (FileNotFoundError, TypeError): + except (FileNotFoundError, IsADirectoryError, TypeError): pass return None