Skip to content

Incorrect type check for seg_len in wfdb.MultiRecord.wrsamp #549

@JunPar

Description

@JunPar

The type check for the seg_len field in wfdb.MultiRecord.wrsamp is not functioning as documented.
According to the official documentation

https://wfdb.readthedocs.io/en/latest/wfdb.html#wfdb.MultiRecord

seg_len is described as having the type List[int].
However, using a list results in the following error:

TypeError: ('Field %s must be one of the following types:', (<class 'int'>, <class 'numpy.int64'>, <class 'numpy.int32'>, <class 'numpy.int16'>, <class 'numpy.int8'>))

Reviewing the source code confirms that the field is validated against integer types rather than a list:

# wfdb.io._header.py L118
SEGMENT_SPECS = pd.DataFrame(
    index=["seg_name", "seg_len"],
    columns=_SPECIFICATION_COLUMNS,
    dtype="object",
    data=[
        [(str), "", None, True, None, None],  # seg_name
        [int_types, " ", "seg_name", True, None, None],  # seg_len
    ],
)

This indicates that the implementation enforces seg_len as a single integer rather than a list of integers, which contradicts the documentation.

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