Skip to content

Physical writes of unsupported formats fail with an unrelated TypeError #777

Done

Description

@tompollard

Writing a record that holds physical signals in a format the writer can't encode fails with an unrelated TypeError, not a message about the format.

import wfdb

record = wfdb.rdrecord("sample-data/binformats", sampto=10)
record.record_name = "out"
record.file_name = [f"out_{i}.dat" for i in range(10)]
record.wrsamp()
  File ".../wfdb/io/record.py", line 1080, in wrsamp
    self.d_signal = self.adc()
  File ".../wfdb/io/_signal.py", line 624, in adc
    return adc_inplace(
  File ".../wfdb/io/_signal.py", line 583, in adc_inplace
    np.copyto(p_signal, d_nan, where=nanlocs)
TypeError: Cannot cast array data from dtype('O') to dtype('float64') according to the rule 'same_kind'

binformats includes formats 8, 61, 160, 310 and 311, which the writer doesn't support. A digital write of the same record fails as it should, with "This library currently only supports writing the following formats". The physical write never reaches that check because it fails earlier, while converting to digital values.

Expected: the same unsupported-format ValueError for physical and digital writes, raised before the conversion. The same failure shows up through SignalRead.write (#776) with kind="physical".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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