Repository navigation
Commit a4f4a14
authored
Fix rr2ann with times and with a symbol column (#612)
`rr2ann` has two problems:
```python
import numpy as np, wfdb
from wfdb.processing.hr import rr2ann
rr2ann(np.array([0.29, 0.57, 1.13]), "t", "atr", fs=100, as_time=True)
wfdb.rdann("t", "atr").sample
# array([ 28, 56, 112]) (expected [29, 57, 113])
rr2ann(np.array([[4, 17], ["V", "N"]]).T, "t", "atr")
# TypeError: the resolved dtypes are not compatible with add.accumulate. Resolved
# (dtype('<U21'), dtype('<U21'), dtype('<U42'))
```
1. With `as_time=True`, times are converted to samples with
`.astype(np.int64)`, which truncates. `0.29 * 100` is
`28.999999999999996`, so the annotation lands one sample early. This now
rounds to the nearest sample.
2. The docstring says a second column can give the annotation symbols.
That makes the array hold strings, and without `as_time` the intervals
go straight into `np.cumsum`, which fails on strings. They are now
converted to integers first (the `as_time` path already converted to
float).
Tests: times that truncate wrongly, intervals with a symbol column (both
fail on `main`), and the docstring example with times and symbols.
`pytest -m "not network"` passes (99 tests), and the docs build passes.3 files changed
Lines changed: 50 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
53 | 56 | | |
54 | 57 | | |
55 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
305 | 305 | | |
306 | 306 | | |
307 | 307 | | |
| 308 | + | |
308 | 309 | | |
309 | | - | |
| 310 | + | |
310 | 311 | | |
311 | | - | |
| 312 | + | |
| 313 | + | |
312 | 314 | | |
313 | 315 | | |
314 | 316 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
372 | 372 | | |
373 | 373 | | |
374 | 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 | + | |
0 commit comments