Skip to content
Open
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
12 changes: 10 additions & 2 deletions imas/backends/netcdf/nc2ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ def run(self, lazy: bool) -> None:
for index, node in indexed_tree_iter(self.ids, target_metadata):
value = data[index]
if value != getattr(var, "_FillValue", None):
if isinstance(value, np.generic):
value = value.item()
# NOTE: bypassing IDSPrimitive.value.setter logic
node._IDSPrimitive__value = value

Expand All @@ -166,10 +168,16 @@ def run(self, lazy: bool) -> None:
# here, we'll let IDSPrimitive.value.setter take care of it:
self.ids[target_metadata.path].value = data

else:
# We need to unpack 0D ints, floats and complex numbers. For better
# performance this check is done outside the for-loop:
elif metadata.ndim or metadata.data_type is IDSDataType.STR:
for index, node in indexed_tree_iter(self.ids, target_metadata):
# NOTE: bypassing IDSPrimitive.value.setter logic
node._IDSPrimitive__value = data[index]
else:
for index, node in indexed_tree_iter(self.ids, target_metadata):
# NOTE: bypassing IDSPrimitive.value.setter logic
node._IDSPrimitive__value = data[index].item() # Unpack 0D value

def validate_variables(self) -> None:
"""Validate that all variables in the netCDF Group exist and match the DD."""
Expand Down Expand Up @@ -365,7 +373,7 @@ def get_child(self, child):
value = var[self.index]

if value is not None:
if isinstance(value, np.ndarray):
if isinstance(value, (np.ndarray, np.generic)):
if value.ndim == 0: # Unpack 0D numpy arrays:
value = value.item()
else:
Expand Down
Loading