Skip to content

Commit

Permalink
Convert user defined filetype to FileType (#79)
Browse files Browse the repository at this point in the history
* convert ud filetype to FileType

* added test for FileType
  • Loading branch information
norlandrhagen authored Apr 11, 2024
1 parent f226093 commit 5435fca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions virtualizarr/kerchunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ def read_kerchunk_references_from_file(
if filetype is None:
filetype = _automatically_determine_filetype(filepath)

# if filetype is user defined, convert to FileType
filetype = FileType(filetype)

if filetype.name.lower() == "netcdf3":
from kerchunk.netCDF3 import NetCDF3ToZarr
refs = NetCDF3ToZarr(filepath, inline_threshold=0).translate()
Expand Down
16 changes: 16 additions & 0 deletions virtualizarr/tests/test_kerchunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import ujson # type: ignore
import xarray as xr
import xarray.testing as xrt
import pytest


from virtualizarr.kerchunk import _automatically_determine_filetype, FileType
from virtualizarr.manifests import ChunkEntry, ChunkManifest, ManifestArray
Expand Down Expand Up @@ -158,3 +160,17 @@ def test_automatically_determine_filetype_netcdf3_netcdf4():
ds.to_netcdf(netcdf4_file_path)
assert FileType("netcdf3") == _automatically_determine_filetype(netcdf3_file_path)
assert FileType("netcdf4") == _automatically_determine_filetype(netcdf4_file_path)




def test_FileType():
# tests if FileType converts user supplied strings to correct filetype
assert 'netcdf3' == FileType("netcdf3").name
assert 'netcdf4' == FileType("netcdf4").name
assert 'grib' == FileType("grib").name
assert 'tiff' == FileType("tiff").name
assert 'fits' == FileType("fits").name
assert 'zarr' == FileType("zarr").name
with pytest.raises(ValueError):
FileType(None)

0 comments on commit 5435fca

Please sign in to comment.