Skip to content

Commit 6e5f6ff

Browse files
committed
improve parser handling of container attrs and scalar vars
1 parent be9e1df commit 6e5f6ff

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

virtualizarr/parsers/dmrpp.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,8 @@ def _parse_variable(self, var_tag: ET.Element) -> ManifestArray:
381381
# Dimension info
382382
dims: dict[str, int] = {}
383383
dimension_tags = self._find_dimension_tags(var_tag)
384-
if not dimension_tags:
385-
raise ValueError("Variable has no dimensions")
384+
# if not dimension_tags:
385+
# # raise ValueError("Variable has no dimensions")
386386
for dim in dimension_tags:
387387
dims.update(self._parse_dim(dim))
388388
# convert DAP dtype to numpy dtype
@@ -407,9 +407,13 @@ def _parse_variable(self, var_tag: ET.Element) -> ManifestArray:
407407
if "fillValue" in chunks_tag.attrib:
408408
fillValue_attrib = chunks_tag.attrib["fillValue"]
409409
array_fill_value = np.array(fillValue_attrib).astype(dtype)[()]
410-
chunkmanifest = self._parse_chunks(chunks_tag, chunks_shape)
410+
if chunks_shape:
411+
chunkmanifest = self._parse_chunks(chunks_tag, chunks_shape)
412+
else:
413+
chunkmanifest = ChunkManifest(entries={}, shape=array_fill_value.shape)
411414
# Filters
412415
codecs = self._parse_filters(chunks_tag, dtype)
416+
413417
# Attributes
414418
attrs: dict[str, Any] = {}
415419
for attr_tag in var_tag.iterfind("dap:Attribute", self._NS):
@@ -449,9 +453,14 @@ def _parse_attribute(self, attr_tag: ET.Element) -> dict[str, Any]:
449453
# DMR++ build information that is not part of the dataset
450454
if attr_tag.attrib["name"] == "build_dmrpp_metadata":
451455
return {}
452-
raise ValueError(
453-
"Nested attributes cannot be assigned to a variable or dataset"
454-
)
456+
else:
457+
container_attr = attr_tag.attrib["name"]
458+
warnings.warn(
459+
"This DMRpp contains a nested attribute "
460+
f"{container_attr}. Nested attributes cannot "
461+
"be assigned to a variable or dataset and will be dropped"
462+
)
463+
return {}
455464
dtype = np.dtype(self._DAP_NP_DTYPE[attr_tag.attrib["type"]])
456465
# if multiple Value tags are present, store as "key": "[v1, v2, ...]"
457466
for value_tag in attr_tag:

0 commit comments

Comments
 (0)