Skip to content

[Bug]: Writing scalar dataset with compound dtype #277

Open
@stephprince

Description

@stephprince

What happened?

See comment in #276 (review) for reference.

This had come up recently in hdmf, but there seems to also be an error with hdmf-zarr writing scalar datasets with a compound dtype.

Steps to Reproduce

from pynwb import NWBFile
from uuid import uuid4
from datetime import datetime

from hdmf_zarr import NWBZarrIO

nwbfile = NWBFile(
    session_description="no description.",
    session_start_time=datetime.now(),
    identifier=str(uuid4()),
)

device = nwbfile.create_device(name="Device", description="no description.")

electrode_group = nwbfile.create_electrode_group(
    name="ElectrodeGroup",
    description="no description.",
    device=device,
    location="unknown",
    position=(1.0, 2.0, 3.0),
)

with NWBZarrIO('test.nwb', 'w') as io:
    io.write(nwbfile)  # errors here
    
with NWBZarrIO('test.nwb', 'r') as io:
    read_nwbfile = io.read()
    
    print(read_nwbfile.electrode_groups['ElectrodeGroup'].position.shape)

Traceback

File "/Users/smprince/.vscode/extensions/ms-python.debugpy-2025.8.0-darwin-arm64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 127, in _run_module_code
    _run_code(code, mod_globals, init_globals, mod_name, mod_spec, pkg_name, script_name)
  File "/Users/smprince/.vscode/extensions/ms-python.debugpy-2025.8.0-darwin-arm64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 118, in _run_code
    exec(code, run_globals)
  File "/Users/smprince/Documents/code/hdmf-zarr/docs/issue_testing.py", line 24, in <module>
    io.write(nwbfile)
  File "/Users/smprince/Documents/code/hdmf/src/hdmf/utils.py", line 578, in func_call
    return func(args[0], **pargs)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/smprince/Documents/code/hdmf-zarr/src/hdmf_zarr/backend.py", line 347, in write
    super(ZarrIO, self).write(**kwargs)
  File "/Users/smprince/Documents/code/hdmf/src/hdmf/utils.py", line 578, in func_call
    return func(args[0], **pargs)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/smprince/Documents/code/hdmf/src/hdmf/backends/io.py", line 99, in write
    self.write_builder(f_builder, **kwargs)
  File "/Users/smprince/Documents/code/hdmf/src/hdmf/utils.py", line 578, in func_call
    return func(args[0], **pargs)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/smprince/Documents/code/hdmf-zarr/src/hdmf_zarr/backend.py", line 522, in write_builder
    self.write_group(
  File "/Users/smprince/Documents/code/hdmf/src/hdmf/utils.py", line 578, in func_call
    return func(args[0], **pargs)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/smprince/Documents/code/hdmf-zarr/src/hdmf_zarr/backend.py", line 621, in write_group
    self.write_group(
  File "/Users/smprince/Documents/code/hdmf/src/hdmf/utils.py", line 578, in func_call
    return func(args[0], **pargs)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/smprince/Documents/code/hdmf-zarr/src/hdmf_zarr/backend.py", line 621, in write_group
    self.write_group(
  File "/Users/smprince/Documents/code/hdmf/src/hdmf/utils.py", line 578, in func_call
    return func(args[0], **pargs)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/smprince/Documents/code/hdmf-zarr/src/hdmf_zarr/backend.py", line 632, in write_group
    self.write_dataset(
  File "/Users/smprince/Documents/code/hdmf/src/hdmf/utils.py", line 578, in func_call
    return func(args[0], **pargs)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/smprince/Documents/code/hdmf-zarr/src/hdmf_zarr/backend.py", line 1186, in write_dataset
    dset = self.__list_fill__(parent, name, data, options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/smprince/Documents/code/hdmf-zarr/src/hdmf_zarr/backend.py", line 1355, in __list_fill__
    data = data[:]  # load the data in case we come from HDF5 or another on-disk data source we don't know
           ~~~~^^^
IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed

Operating System

Windows

Python Version

3.12

Package Versions

No response

Metadata

Metadata

Assignees

Labels

category: bugerrors in the code or code behaviorpriority: mediumnon-critical problem and/or affecting only a small set of users

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions