oruebel / ndx-icephys-meta

NWB extensions for origanizing intracellular electrophysiology metadata
Other
6 stars 0 forks source link

Validation error in example file #57

Open rly opened 4 years ago

rly commented 4 years ago

After resolving the validation error in https://github.com/oruebel/ndx-icephys-meta/issues/21 , another validation error appears: the 'colnames' attribute of /general/intracellular_ephys/intracellular_recordings/ is empty which raises an IndexError.

I raised this issue in https://github.com/hdmf-dev/hdmf/issues/317

oruebel commented 4 years ago

Does this mean we currently do not allow DynamicTables with just the id column but no data?

rly commented 4 years ago

Correct.

from pynwb import NWBFile, NWBHDF5IO, validate
from pynwb.core import DynamicTable
from datetime import datetime

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

table = DynamicTable(name='name',
                     description='description')
table.add_row(id=1)

nwbfile.add_acquisition(table)

filename = 'nwbfile.nwb'

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

with NWBHDF5IO(filename, 'r') as io:
    validate(io)
    nwbfile = io.read()

results in the error IndexError: index 0 is out of bounds for axis 0 with size 0

rly commented 4 years ago

Also note that if no row is added, the table is not even written to disk.

oruebel commented 4 years ago

results in the error IndexError: index 0 is out of bounds for axis 0 with size

although that seems to be just an issue with the get_type function in the validator, i.e., the issue is with the validate(io) call; the io.read() seems to work fine. The fix for that error should be.

diff --git a/src/hdmf/validate/validator.py b/src/hdmf/validate/validator.py
index efcbb26..cea11c5 100644
--- a/src/hdmf/validate/validator.py
+++ b/src/hdmf/validate/validator.py
@@ -105,7 +105,10 @@ def get_type(data):
     elif isinstance(data, ReferenceBuilder):
         return 'object'
     elif isinstance(data, np.ndarray):
-        return get_type(data[0])
+        if len(data) > 0:
+            return get_type(data[0])
+        else:
+            return data.dtype
     if not hasattr(data, '__len__'):
         return type(data).__name__
     else: