From a69b795450ceb67abe7b13e34b2611f7163d7b22 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Mon, 3 Nov 2025 21:31:09 +0100 Subject: [PATCH] convert lists to numpy arrays (in order to handle non-1D lists) --- dap/utils/bsreadext.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/dap/utils/bsreadext.py b/dap/utils/bsreadext.py index 8c1baa1..dce3a9f 100644 --- a/dap/utils/bsreadext.py +++ b/dap/utils/bsreadext.py @@ -1,3 +1,4 @@ +import numpy as np from bsread.sender import Sender, PUB @@ -18,10 +19,20 @@ def pack_bsread_data(orig, prefix, skip=None): continue if isinstance(v, bool): v = int(v) - elif isinstance(v, list) and not v: - v = None + elif isinstance(v, list): + # bsread fails for empty lists and non-1D lists + v = list_to_array(v) data[f"{prefix}:{k}"] = v return data +def list_to_array(x): + try: + # let numpy figure out the dtype + return np.array(x) + except ValueError: + # the above fails for ragged lists, which need to be object arrays + return np.array(x, dtype=object) + +