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

Use a set to avoid duplicate var names from kerchunk #179

Merged
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
4 changes: 2 additions & 2 deletions virtualizarr/kerchunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ def find_var_names(ds_reference_dict: KerchunkStoreRefs) -> list[str]:
"""Find the names of zarr variables in this store/group."""

refs = ds_reference_dict["refs"]
found_var_names = [key.split("/")[0] for key in refs.keys() if "/" in key]
return found_var_names
found_var_names = {key.split("/")[0] for key in refs.keys() if "/" in key}
return list(found_var_names)


def extract_array_refs(
Expand Down
13 changes: 12 additions & 1 deletion virtualizarr/tests/test_kerchunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import xarray as xr
import xarray.testing as xrt

from virtualizarr.kerchunk import FileType, _automatically_determine_filetype
from virtualizarr.kerchunk import FileType, find_var_names, _automatically_determine_filetype, KerchunkStoreRefs
from virtualizarr.manifests import ChunkManifest, ManifestArray
from virtualizarr.xarray import dataset_from_kerchunk_refs

Expand Down Expand Up @@ -266,3 +266,14 @@ def test_FileType():
assert "zarr" == FileType("zarr").name
with pytest.raises(ValueError):
FileType(None)


def test_no_duplicates_find_var_names():
"""Verify that we get a deduplicated list of var names"""
ref_dict = {
"refs": {
"x/something": {},
"x/otherthing": {}
}
}
assert len(find_var_names(ref_dict)) == 1
Loading