NeurodataWithoutBorders / nwbinspector

Tool to help inspect NWB files for compliance with NWB Best Practices
https://nwbinspector.readthedocs.io/
Other
17 stars 10 forks source link

[Bug]: nwbinspector fails when there is an empty dataset #304

Open bendichter opened 2 years ago

bendichter commented 2 years ago

What happened?

When you write an empty dataset and pass it to nwbinspector it errors. I would like to handle this and create an InspectorMessage when such a dataset is detected

Steps to Reproduce

from pynwb import NWBFile, NWBHDF5IO
from datetime import datetime

nwbfile = NWBFile(session_description='ADDME',
                  identifier='ADDME',
                  session_start_time=datetime.now().astimezone(),
                  keywords=[])

with NWBHDF5IO('test_keywords.nwb', 'w') as io:
    io.write(nwbfile)

### in command line
nwbinspector test_keywords.nwb

Traceback

Traceback (most recent call last):                                              
  File "/Users/bendichter/opt/miniconda3/bin/nwbinspector", line 8, in <module>
    sys.exit(inspect_all_cli())
  File "/Users/bendichter/opt/miniconda3/lib/python3.9/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/Users/bendichter/opt/miniconda3/lib/python3.9/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/Users/bendichter/opt/miniconda3/lib/python3.9/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/bendichter/opt/miniconda3/lib/python3.9/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/Users/bendichter/opt/miniconda3/lib/python3.9/site-packages/nwbinspector/nwbinspector.py", line 266, in inspect_all_cli
    messages = list(
  File "/Users/bendichter/opt/miniconda3/lib/python3.9/site-packages/nwbinspector/nwbinspector.py", line 446, in inspect_all
    for message in inspect_nwb(nwbfile_path=nwbfile_path, checks=checks, driver=driver):
  File "/Users/bendichter/opt/miniconda3/lib/python3.9/site-packages/nwbinspector/nwbinspector.py", line 523, in inspect_nwb
    validation_errors = pynwb.validate(io=io)
  File "/Users/bendichter/dev/hdmf/src/hdmf/utils.py", line 652, in func_call
    return func(**pargs)
  File "/Users/bendichter/dev/pynwb/src/pynwb/validate.py", line 124, in validate
    validation_errors = _validate_helper(io=io, namespace=namespace or CORE_NAMESPACE)
  File "/Users/bendichter/dev/pynwb/src/pynwb/validate.py", line 29, in _validate_helper
    return validator.validate(builder)
  File "/Users/bendichter/dev/hdmf/src/hdmf/utils.py", line 648, in func_call
    return func(args[0], **pargs)
  File "/Users/bendichter/dev/hdmf/src/hdmf/validate/validator.py", line 248, in validate
    return validator.validate(builder)
  File "/Users/bendichter/dev/hdmf/src/hdmf/utils.py", line 648, in func_call
    return func(args[0], **pargs)
  File "/Users/bendichter/dev/hdmf/src/hdmf/validate/validator.py", line 423, in validate
    errors.extend(self.__validate_children(builder))
  File "/Users/bendichter/dev/hdmf/src/hdmf/validate/validator.py", line 449, in __validate_children
    yield from self.__validate_child_builder(child_spec, child_builder, parent_builder)
  File "/Users/bendichter/dev/hdmf/src/hdmf/validate/validator.py", line 498, in __validate_child_builder
    yield from child_validator.validate(child_builder)
  File "/Users/bendichter/dev/hdmf/src/hdmf/utils.py", line 648, in func_call
    return func(args[0], **pargs)
  File "/Users/bendichter/dev/hdmf/src/hdmf/validate/validator.py", line 423, in validate
    errors.extend(self.__validate_children(builder))
  File "/Users/bendichter/dev/hdmf/src/hdmf/validate/validator.py", line 449, in __validate_children
    yield from self.__validate_child_builder(child_spec, child_builder, parent_builder)
  File "/Users/bendichter/dev/hdmf/src/hdmf/validate/validator.py", line 498, in __validate_child_builder
    yield from child_validator.validate(child_builder)
  File "/Users/bendichter/dev/hdmf/src/hdmf/utils.py", line 648, in func_call
    return func(args[0], **pargs)
  File "/Users/bendichter/dev/hdmf/src/hdmf/validate/validator.py", line 386, in validate
    dtype = get_type(data)
  File "/Users/bendichter/dev/hdmf/src/hdmf/validate/validator.py", line 127, in get_type
    return get_type(data[0])
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "/Users/bendichter/opt/miniconda3/lib/python3.9/site-packages/h5py/_hl/dataset.py", line 777, in __getitem__
    selection = sel.select(self.shape, args, dataset=self)
  File "/Users/bendichter/opt/miniconda3/lib/python3.9/site-packages/h5py/_hl/selections.py", line 82, in select
    return selector.make_selection(args)
  File "h5py/_selector.pyx", line 272, in h5py._selector.Selector.make_selection
  File "h5py/_selector.pyx", line 151, in h5py._selector.Selector.apply_args
IndexError: Index (0) out of range for empty dimension

Operating System

macOS

Python Executable

Conda

Python Version

3.7

Usage

Command Line Interface

Were you streaming with ROS3?

No

Package Versions

No response

Code of Conduct

bendichter commented 2 years ago

On second thought, this looks like an issue with pynwb.validate

bendichter commented 2 years ago

https://github.com/hdmf-dev/hdmf/issues/788