Skip to content

Commit 184f4fb

Browse files
author
Benjamin Moody
committed
_digi_nan: use a dictionary instead of "if" statements.
This will also raise an exception for unknown formats, rather than silently returning None.
1 parent b83fad5 commit 184f4fb

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

wfdb/io/_signal.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,21 @@
7777
"8": (-(2**31), 2**31 - 1),
7878
}
7979

80+
# Digital value used to represent a missing/invalid sample, in each of the
81+
# WFDB dat formats.
82+
INVALID_SAMPLE_VALUE = {
83+
"80": -(2**7),
84+
"310": -(2**9),
85+
"311": -(2**9),
86+
"212": -(2**11),
87+
"16": -(2**15),
88+
"61": -(2**15),
89+
"160": -(2**15),
90+
"24": -(2**23),
91+
"32": -(2**31),
92+
"8": None,
93+
}
94+
8095

8196
class SignalMixin(object):
8297
"""
@@ -1874,25 +1889,7 @@ def _digi_nan(fmt):
18741889
"""
18751890
if isinstance(fmt, list):
18761891
return [_digi_nan(f) for f in fmt]
1877-
1878-
if fmt == "80":
1879-
return -128
1880-
if fmt == "310":
1881-
return -512
1882-
if fmt == "311":
1883-
return -512
1884-
elif fmt == "212":
1885-
return -2048
1886-
elif fmt == "16":
1887-
return -32768
1888-
elif fmt == "61":
1889-
return -32768
1890-
elif fmt == "160":
1891-
return -32768
1892-
elif fmt == "24":
1893-
return -8388608
1894-
elif fmt == "32":
1895-
return -2147483648
1892+
return INVALID_SAMPLE_VALUE[fmt]
18961893

18971894

18981895
def est_res(signals):

0 commit comments

Comments
 (0)