Skip to content

Commit 4403681

Browse files
committed
remove recursion from by default.
1 parent 0c612f9 commit 4403681

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/pynxtools/nomad/parser.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,22 @@ def _get_value(hdf_node):
143143
if hdf_value.dtype.kind in "iufc":
144144
return hdf_value
145145
if len(hdf_value.shape) > 0:
146+
# Variable-length UTF-8 / object arrays
147+
if hdf_value.dtype.kind == "O":
148+
# Recursively decode nested lists if needed
149+
def decode_array(arr):
150+
result = []
151+
for x in arr:
152+
if isinstance(x, (np.ndarray, list)):
153+
result.append(decode_array(x))
154+
else:
155+
result.append(str(decode_or_not(x)))
156+
return result
146157

147-
def recurse(x):
148-
if hasattr(x, "shape") and len(x.shape) > 0:
149-
return [recurse(i) for i in x]
150-
else:
151-
return str(decode_or_not(x))
158+
return decode_array(hdf_value)
152159

153-
return str(recurse(hdf_value))
160+
# Fallback for other arrays
161+
return str([i for i in hdf_value.astype(str)])
154162

155163
return hdf_node[()].decode()
156164

0 commit comments

Comments
 (0)