Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
luiztauffer opened this issue Nov 18, 2019 · 3 comments · Fixed by #203
Closed

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

luiztauffer opened this issue Nov 18, 2019 · 3 comments · Fixed by #203
Labels
category: bug errors in the code or code behavior

Comments

@luiztauffer
Copy link

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

  • [x ] Have you ensured the feature or change was not already reported ?
  • [ x] Have you included a brief and descriptive title?
  • [ x] Have you included a clear description of the problem you are trying to solve?
  • [ x] Have you included a minimal code snippet that reproduces the issue you are encountering?
  • [ x] Have you checked our Contributing document?
@rly
Copy link
Contributor

rly commented Nov 19, 2019

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
Copy link
Author

@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
Copy link
Contributor

rly commented Nov 19, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: bug errors in the code or code behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants