Skip to content

Commit

Permalink
Merge pull request #416 into main
Browse files Browse the repository at this point in the history
Avoid ambiguous backslashes in strings, which are confusing and
generate warnings in newer python versions.
  • Loading branch information
Benjamin Moody committed Sep 1, 2022
2 parents 21a7b52 + 9b2d6c3 commit b1c3284
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions tests/test_annotation.py
Expand Up @@ -44,7 +44,7 @@ def test_1(self):
target_aux_note = [None] * nannot

RXannot = re.compile(
"[ \t]*(?P<time>[\[\]\w\.:]+) +(?P<sample>\d+) +(?P<symbol>.) +(?P<subtype>\d+) +(?P<chan>\d+) +(?P<num>\d+)\t?(?P<aux_note>.*)"
r"[ \t]*(?P<time>[\[\]\w\.:]+) +(?P<sample>\d+) +(?P<symbol>.) +(?P<subtype>\d+) +(?P<chan>\d+) +(?P<num>\d+)\t?(?P<aux_note>.*)"
)

for i in range(0, nannot):
Expand Down Expand Up @@ -117,7 +117,7 @@ def test_2(self):
target_aux_note = [None] * nannot

RXannot = re.compile(
"[ \t]*(?P<time>[\[\]\w\.:]+) +(?P<sample>\d+) +(?P<symbol>.) +(?P<subtype>\d+) +(?P<chan>\d+) +(?P<num>\d+)\t?(?P<aux_note>.*)"
r"[ \t]*(?P<time>[\[\]\w\.:]+) +(?P<sample>\d+) +(?P<symbol>.) +(?P<subtype>\d+) +(?P<chan>\d+) +(?P<num>\d+)\t?(?P<aux_note>.*)"
)

for i in range(0, nannot):
Expand Down Expand Up @@ -188,7 +188,7 @@ def test_3(self):
target_aux_note = [None] * nannot

RXannot = re.compile(
"[ \t]*(?P<time>[\[\]\w\.:]+) +(?P<sample>\d+) +(?P<symbol>.) +(?P<subtype>\d+) +(?P<chan>\d+) +(?P<num>\d+)\t?(?P<aux_note>.*)"
r"[ \t]*(?P<time>[\[\]\w\.:]+) +(?P<sample>\d+) +(?P<symbol>.) +(?P<subtype>\d+) +(?P<chan>\d+) +(?P<num>\d+)\t?(?P<aux_note>.*)"
)

for i in range(0, nannot):
Expand Down
6 changes: 3 additions & 3 deletions wfdb/io/annotation.py
Expand Up @@ -385,7 +385,7 @@ def check_field(self, field):

# Field specific checks
if field == "record_name":
if bool(re.search("[^-\w]", self.record_name)):
if bool(re.search(r"[^-\w]", self.record_name)):
raise ValueError(
"record_name must only comprise of letters, digits, hyphens, and underscores."
)
Expand Down Expand Up @@ -2394,9 +2394,9 @@ def update_extra_fields(subtype, chan, num, aux_note, update):
return subtype, chan, num, aux_note


rx_fs = re.compile("## time resolution: (?P<fs>\d+\.?\d*)")
rx_fs = re.compile(r"## time resolution: (?P<fs>\d+\.?\d*)")
rx_custom_label = re.compile(
"(?P<label_store>\d+) (?P<symbol>\S+) (?P<description>.+)"
r"(?P<label_store>\d+) (?P<symbol>\S+) (?P<description>.+)"
)


Expand Down
10 changes: 5 additions & 5 deletions wfdb/io/record.py
Expand Up @@ -421,7 +421,7 @@ def check_field(self, field, required_channels="all"):
# Record specification fields
elif field == "record_name":
# Allow letters, digits, hyphens, and underscores.
accepted_string = re.match("[-\w]+", self.record_name)
accepted_string = re.match(r"[-\w]+", self.record_name)
if (
not accepted_string
or accepted_string.string != self.record_name
Expand Down Expand Up @@ -461,7 +461,7 @@ def check_field(self, field, required_channels="all"):

if field == "file_name":
# Check for file_name characters
accepted_string = re.match("[-\w]+\.?[\w]+", item[ch])
accepted_string = re.match(r"[-\w]+\.?[\w]+", item[ch])
if (
not accepted_string
or accepted_string.string != item[ch]
Expand Down Expand Up @@ -505,7 +505,7 @@ def check_field(self, field, required_channels="all"):
"baseline values must be between -2147483648 (-2^31) and 2147483647 (2^31 -1)"
)
elif field == "units":
if re.search("\s", item[ch]):
if re.search(r"\s", item[ch]):
raise ValueError(
"units strings may not contain whitespaces."
)
Expand All @@ -520,7 +520,7 @@ def check_field(self, field, required_channels="all"):
"block_size values must be non-negative integers"
)
elif field == "sig_name":
if re.search("\s", item[ch]):
if re.search(r"\s", item[ch]):
raise ValueError(
"sig_name strings may not contain whitespaces."
)
Expand All @@ -534,7 +534,7 @@ def check_field(self, field, required_channels="all"):
# Segment names must be alphanumerics or just a single '~'
if item[ch] == "~":
continue
accepted_string = re.match("[-\w]+", item[ch])
accepted_string = re.match(r"[-\w]+", item[ch])
if (
not accepted_string
or accepted_string.string != item[ch]
Expand Down

0 comments on commit b1c3284

Please sign in to comment.