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) + +