Repository navigation
Commit 7c4dcf5
authored
Accept sample numbers stored as floats in wrann (#625)
Fixes #201.
`wrann` failed with an unhelpful error when `sample` was a float array,
which is easy to get from a detector or model:
```python
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`.3 files changed
Lines changed: 90 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
565 | 565 | | |
566 | 566 | | |
567 | 567 | | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
568 | 592 | | |
569 | 593 | | |
570 | 594 | | |
| |||
1156 | 1180 | | |
1157 | 1181 | | |
1158 | 1182 | | |
1159 | | - | |
1160 | | - | |
1161 | | - | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
1162 | 1188 | | |
1163 | | - | |
| 1189 | + | |
1164 | 1190 | | |
1165 | 1191 | | |
1166 | 1192 | | |
| |||
1734 | 1760 | | |
1735 | 1761 | | |
1736 | 1762 | | |
1737 | | - | |
| 1763 | + | |
| 1764 | + | |
1738 | 1765 | | |
1739 | 1766 | | |
1740 | 1767 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| |||
360 | 362 | | |
361 | 363 | | |
362 | 364 | | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
363 | 419 | | |
364 | 420 | | |
365 | 421 | | |
| |||
0 commit comments