From eb46d65825e47a6e842fb96acddd8f15eb7ffe10 Mon Sep 17 00:00:00 2001 From: Maarten Sebregts Date: Tue, 8 Jul 2025 14:24:23 +0200 Subject: [PATCH] Ensure that 0D numpy arrays are unpacked when filling lazy loaded IDS from netCDF files ```python >>> entry = imas.DBEntry("ascii.nc", "r") >>> eq = entry.get("equilibrium", autoconvert=False, lazy=True) >>> # Previous behaviour: >>> eq.ids_properties.homogeneous_time ndarray(array(1, dtype=int32)) >>> # New behaviour, matches with non-lazy IDS: >>> eq.ids_properties.homogeneous_time int(1) ``` --- imas/backends/netcdf/nc2ids.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/imas/backends/netcdf/nc2ids.py b/imas/backends/netcdf/nc2ids.py index 306c128..1b1dbfe 100644 --- a/imas/backends/netcdf/nc2ids.py +++ b/imas/backends/netcdf/nc2ids.py @@ -366,9 +366,12 @@ def get_child(self, child): if value is not None: if isinstance(value, np.ndarray): - # Convert the numpy array to a read-only view - value = value.view() - value.flags.writeable = False + if value.ndim == 0: # Unpack 0D numpy arrays: + value = value.item() + else: + # Convert the numpy array to a read-only view + value = value.view() + value.flags.writeable = False # NOTE: bypassing IDSPrimitive.value.setter logic child._IDSPrimitive__value = value