hdmf-dev / hdmf

The Hierarchical Data Modeling Framework
http://hdmf.readthedocs.io
Other
47 stars 26 forks source link

Getting TypeError: incorrect type for 'bool' attribute in extension #200

Closed luiztauffer closed 4 years ago

luiztauffer commented 4 years ago

I’m having a problem creating an extension, more specifically, to create an attribute of type bool.

On the list of valid primary dtypes, I get: {'isodatetime', 'datetime64', 'region', 'int8', 'int16', 'bool', 'int', 'ascii', 'int32', 'text', 'bytes', 'int64', 'utf-8', 'double', 'utf', 'datetime', 'uint32', 'uint', 'uint64', 'uint16', 'object', 'numeric', 'float32', 'float', 'short', 'float64', 'long', 'uint8', 'utf8'}

Then I try to add an attribute of type bool:

    LabMetaData_ext.add_attribute(
        name='high_pass_filtered',
        doc='binary variable as to whether raw data was high-pass filtered or not',
        dtype='bool',
        shape=None,
    )

Here’s the full code.

When I run this test, it apparently works well in saving the nwb file with the new extension, I can even open the file with HDFView, but fails opening the new file with NWBHDF5IO. The error:

Traceback (most recent call last):
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\build\map.py", line 1207, in construct
    obj.__init__(**kwargs)
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\utils.py", line 436, in func_call
    raise_from(ExceptionType(msg), None)
  File "<string>", line 3, in raise_from
TypeError: incorrect type for 'high_pass_filtered' (got 'bool_', expected 'bool')

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "test.py", line 28, in <module>
    nwb = io.read()
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\backends\hdf5\h5tools.py", line 293, in read
    return call_docval_func(super(HDF5IO, self).read, kwargs)
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\utils.py", line 327, in call_docval_func
    return func(*fargs, **fkwargs)
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\utils.py", line 438, in func_call
    return func(self, **parsed['args'])
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\backends\io.py", line 35, in read
    container = self.__manager.construct(f_builder)
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\utils.py", line 438, in func_call
    return func(self, **parsed['args'])
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\build\map.py", line 208, in construct
    result = self.__type_map.construct(builder, self, None)
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\utils.py", line 438, in func_call
    return func(self, **parsed['args'])
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\build\map.py", line 1712, in construct
    return attr_map.construct(builder, build_manager, parent)
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\utils.py", line 438, in func_call
    return func(self, **parsed['args'])
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\build\map.py", line 1175, in construct
    subspecs = self.__get_subspec_values(builder, self.spec, manager)
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\build\map.py", line 1117, in __get_subspec_values
    self.__get_sub_builders(groups, spec.groups, manager, ret)
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\build\map.py", line 1155, in __get_sub_builders
    ret.update(self.__get_subspec_values(sub_builder, subspec, manager))
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\build\map.py", line 1117, in __get_subspec_values
    self.__get_sub_builders(groups, spec.groups, manager, ret)
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\build\map.py", line 1147, in __get_sub_builders
    sub_builder = self.__flatten(sub_builder, subspec, manager)
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\build\map.py", line 1160, in __flatten
    tmp = [manager.construct(b) for b in sub_builder]
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\build\map.py", line 1160, in <listcomp>
    tmp = [manager.construct(b) for b in sub_builder]
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\utils.py", line 438, in func_call
    return func(self, **parsed['args'])
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\build\map.py", line 204, in construct
    result = self.__type_map.construct(builder, self, parent)
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\utils.py", line 438, in func_call
    return func(self, **parsed['args'])
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\build\map.py", line 1712, in construct
    return attr_map.construct(builder, build_manager, parent)
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\utils.py", line 438, in func_call
    return func(self, **parsed['args'])
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\build\map.py", line 1210, in construct
    raise_from(Exception(msg), ex)
  File "<string>", line 3, in raise_from
Exception: Could not construct LabMetaData_ext object

I’m guessing the source is here?

TypeError: incorrect type for 'high_pass_filtered' (got 'bool_', expected 'bool')

Does anyone have a hint how to solve it?

Python Version: 3.7
Operating System: Windows
HDMF Version: 1.3.3

Checklist

rly commented 4 years ago

Hi @luiztauffer . Please try out the latest 1.4.0 version of HDMF and let me know if that does or does not fix the error.

luiztauffer commented 4 years ago

@rly

When using hdmf=1.4.0 and pynwb=1.1.2, I get the following installation error: ERROR: pynwb 1.1.2 has requirement hdmf==1.3.3, but you'll have hdmf 1.4.0 which is incompatible. and when running the test script, I get:

Traceback (most recent call last):
  File "test.py", line 5, in <module>
    nwb = NWBFile('session_description', 'identifier', datetime.now().astimezone())
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\utils.py", line 461, in func_call
    return func(self, **parsed['args'])
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\pynwb\file.py", line 298, in __init__
    super(NWBFile, self).__init__(*pargs, **pkwargs)
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\utils.py", line 452, in func_call
    allow_extra=allow_extra)
  File "C:\Users\Luiz\Anaconda3\envs\nwbn_conversion\lib\site-packages\hdmf\utils.py", line 164, in __parse_args
    raise TypeError('Expected at most %s arguments, got %s' % (len(validator), len(args) + len(kwargs)))
TypeError: Expected at most 1 arguments, got 2

I tested it now with the most current github version pynwb-1.1.2.post0.dev7 and it is working! Thanks for the fix!

rly commented 4 years ago

Awesome. We haven't released a new version of pynwb which would use the latest hdmf yet (we will soon), so yes, you'll have to use the dev version in the meantime.