Skip to content

Commit

Permalink
fix warning from scipy backend guess_can_open on directory
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
germasch committed Dec 19, 2024
1 parent 29fe679 commit 4505e6f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion xarray/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 4505e6f

Please sign in to comment.