Skip to content

Set unit as optional for Groups extending TimeSeries #630

@luiztauffer

Description

@luiztauffer

I’m creating a couple of NWBGroupSpec classes that extend TimeSeries. For those classes, the data has no physical unit, and I’d like to make that attribute not required, or at least set a default value for it. I’ve tried to overwrite the data Dataset, see here, giving it an optional unit attribute, but I keep getting this error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[3], line 6
----> 6 latent_space_series = LatentSpaceSeries(
      7     name="LatentSpaceSeries",
      8     data=latent_data,
      9     rate=10.,
     10 )

File ~/anaconda3/envs/vame-desktop/lib/python3.12/site-packages/hdmf/utils.py:667, in docval.<locals>.dec.<locals>.func_call(*args, **kwargs)
    666 def func_call(*args, **kwargs):
--> 667     pargs = _check_args(args, kwargs)
    668     return func(args[0], **pargs)

File ~/anaconda3/envs/vame-desktop/lib/python3.12/site-packages/hdmf/utils.py:660, in docval.<locals>.dec.<locals>._check_args(args, kwargs)
    658     if parse_err:
    659         msg = '%s: %s' % (func.__qualname__, ', '.join(parse_err))
--> 660         raise ExceptionType(msg)
    662 return parsed['args']

TypeError: CustomClassGenerator.set_init.<locals>.__init__: missing argument 'unit'

Code to reproduce here.

How can solve this?

I can get rid of this error defining an attribute for the Group like this:

latent_space_series = NWBGroupSpec(
        neurodata_type_def="LatentSpaceSeries",
        neurodata_type_inc="TimeSeries",
        ...
        attributes=[
            NWBAttributeSpec(
                name="unit",
                doc="The physical unit of the data.",
                dtype="text",
                required=False,
                default_value="n/a",
            ),
        ],
    )

but, is this correct? According to the TimeSeries schema, unit is an attribute of the dataset, not of the group.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions