Skip to content

Accept sample numbers stored as floats in wrann - #625

Open
tompollard wants to merge 2 commits into
mainfrom
tp/wrann-float-samples
Open

tompollard wants to merge 2 commits into
mainfrom
tp/wrann-float-samples

Conversation

@tompollard

Copy link
Copy Markdown
Member

Fixes #201.

wrann failed with an unhelpful error when sample was a float array, which is easy to get from a detector or model:

wfdb.wrann("100", "atr", np.array([100.0, 2500.0]), symbol=["N", "V"])
# TypeError: ufunc 'bitwise_and' not supported for the input types, ...

The float values reached the bit operations in field2bytes, which only work on integers.

  • Float sample numbers are now accepted if they are all whole numbers, and written as integers. The file is identical to the one written from an integer array, and the caller's array isn't changed.
  • Other floats (such as 20.5, NaN or infinity) raise ValueError: The 'sample' field must only contain whole numbers.
  • Other dtypes are handled as before (for example, object arrays of Python ints still work).

This matches the other integer fields (subtype, chan, num and label_store), which already accept whole-number floats.

Tests: a float array gives the same file as an integer array (including a gap large enough to need a SKIP), and fractions, NaN and infinity raise a ValueError. All four fail on main.

wrann failed with "ufunc 'bitwise_and' not supported" when sample was a
float array, which is easy to get from a detector or model. Accept float
sample numbers if they are all whole numbers, and convert them to
integers when writing, without changing the caller's array. Other floats
(fractions, NaN, infinity) raise a ValueError. Other dtypes are handled
as before.
On x86, np.mod(inf, 1) sets the invalid flag, which the tests turn into
a FloatingPointError. Reject NaN and infinity first, and compare finite
values with their rounded values instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Subelements of the symbol field must be strings of length 1 to 3 error

1 participant