Skip to content

Commit

Permalink
Allow 'getFloat' to scrape a number from a string with other text (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
pipliggins committed Jun 14, 2023
1 parent b021f53 commit 67a2be6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions adtl/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from backports import zoneinfo # noqa

import pint
import re


def isNotNull(value):
Expand Down Expand Up @@ -44,6 +45,9 @@ def getFloat(value, set_decimal=None, separator=None):
elif separator in value_int:
value = value_int.replace(separator, "") + "." + fraction

values = [float(d) for d in re.findall(r"[-+]?\d*\.?\d+", value)]
value = values[0] if len(values) == 1 else value

try:
return float(value)
except ValueError:
Expand Down
1 change: 1 addition & 0 deletions tests/test_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def test_endDate(test_enddate_start, test_enddate_duration, expected):
(("1.234,5", ",", "."), 1234.5),
(("1.567.923,66", ",", "."), 1567923.66),
(('" -1+1"', None, None), "-1+1"),
((" -3 - Moderate Sedation", None, None), -3),
],
)
def test_getFloat(badfloat, expected):
Expand Down

0 comments on commit 67a2be6

Please sign in to comment.