Skip to content

Commit

Permalink
Merge pull request #4 from dylanwal/bug_fix
Browse files Browse the repository at this point in the history
update to scientific notation handling
  • Loading branch information
dylanwal authored Oct 22, 2022
2 parents f1638f4 + c964906 commit 9741250
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
9 changes: 9 additions & 0 deletions dev_files/simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import logging

from unit_parse import parser, logger

logger.setLevel(logging.DEBUG)

result = parser("3.6E+00004 mg/L")
print(result)

2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = unit_parse
version = 0.1.6
version = 0.1.7
description = Parse units from strings. From mess to order!
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
4 changes: 2 additions & 2 deletions src/unit_parse/pre_processing_substitution.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ def sub_sci_notation(text_in: str) -> str:
text_in = text_in.replace(exp, exp_new)

# remove leading zero in powers ( 5*10**-05 --> 5*10**-5)
text_in = re.sub('(?<=[*]{2}[-])0(?=[0-9])', "", text_in) # neg. power
text_in = re.sub('(?<=[*]{2})0(?=[0-9])', "", text_in) # pos. power
text_in = re.sub('(?<=[*]{2}[-])0+(?=[0-9])', "", text_in) # neg. power
text_in = re.sub('(?<=[*]{2})0+(?=[0-9])', "", text_in) # pos. power

return text_in.strip()

Expand Down
1 change: 1 addition & 0 deletions tests/test_pre_processing_substitution.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def test_remove_words(input_, output_):
['5.3e1 g/mol', '5.3*10**1 g/mol'],
['5.3E1 g/mol', '5.3*10**1 g/mol'],
['5.3 109 g/mol', '5.3*10**9 g/mol'],
["3.6E+00004 mg/L", "3.6*10**4 mg/L"],

# negative control (no changes made)
['5.3*10**1 g/mol', '5.3*10**1 g/mol'],
Expand Down

0 comments on commit 9741250

Please sign in to comment.