Skip to content
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

Align accepted filetypes with docstring description #361

Merged
merged 8 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions virtualizarr/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def open_virtual_dataset(
----------
filepath : str, default None
File path to open as a set of virtualized zarr arrays.
filetype : FileType, default None
filetype : FileType or str, default None
Type of file to be opened. Used to determine which kerchunk file format backend to use.
Can be one of {'netCDF3', 'netCDF4', 'HDF', 'TIFF', 'GRIB', 'FITS', 'dmrpp', 'zarr_v3', 'kerchunk'}.
If not provided will attempt to automatically infer the correct filetype from header bytes.
Expand Down Expand Up @@ -182,13 +182,16 @@ def open_virtual_dataset(
if backend and filetype:
raise ValueError("Cannot pass both a filetype and an explicit VirtualBackend")

if filetype is not None:
# if filetype is user defined, convert to FileType
filetype = FileType(filetype)
else:
if filetype is None:
filetype = automatically_determine_filetype(
filepath=filepath, reader_options=reader_options
)
elif isinstance(filetype, str):
# if filetype is a user defined string, convert to FileType
filetype = FileType(filetype.lower())
elif not isinstance(filetype, FileType):
raise ValueError("Filetype must be a valid string or FileType")

if backend:
backend_cls = backend
else:
Expand Down
5 changes: 5 additions & 0 deletions virtualizarr/tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,14 @@ def test_explicit_filetype(self, netcdf4_file):
with pytest.raises(ValueError):
open_virtual_dataset(netcdf4_file, filetype="unknown")

with pytest.raises(ValueError):
open_virtual_dataset(netcdf4_file, filetype=ManifestArray)

with pytest.raises(NotImplementedError):
open_virtual_dataset(netcdf4_file, filetype="grib")

open_virtual_dataset(netcdf4_file, filetype="netCDF4")

def test_explicit_filetype_and_backend(self, netcdf4_file):
with pytest.raises(ValueError):
open_virtual_dataset(
Expand Down
Loading