aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2023-01-19 14:16:27 +0000
committerArun Isaac2023-01-19 14:18:34 +0000
commit606130cd1c2d3267233a7f09d4ac1d68a5e5f82b (patch)
treef5cd021e7c2514fae25aa0a081b24b94ec74ce53
parent88070363558aa8c8f55021d8db1c410007d8854b (diff)
downloadgenenetwork3-606130cd1c2d3267233a7f09d4ac1d68a5e5f82b.tar.gz
search: Apply SI suffix only if last character is an actual suffix.
Prior to this commit, when there was no SI suffix (such as in a plain suffix-less number), the last digit would be dropped! * gn3/api/search.py (apply_si_suffix): Apply SI suffix only if last character is an actual suffix.
-rw-r--r--gn3/api/search.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/gn3/api/search.py b/gn3/api/search.py
index 3846aa7..03f257d 100644
--- a/gn3/api/search.py
+++ b/gn3/api/search.py
@@ -150,7 +150,10 @@ def parse_range(range_string: str) -> tuple[Maybe[str], Maybe[str]]:
def apply_si_suffix(location: str) -> int:
"""Apply SI suffixes kilo, mega, giga and convert to bases."""
suffixes = {"k": 3, "m": 6, "g": 9}
- return int(float(location[:-1])*10**suffixes.get(location[-1].lower(), 0))
+ if location[:-1] in suffixes:
+ return int(float(location[:-1])*10**suffixes[location[-1].lower()])
+ else:
+ return int(location)
def parse_location_field(species_query: xapian.Query,