[Bug]: human_to_eng() parses MHz incorrectly #12

Closed
opened 2026-04-17 11:34:22 +00:00 by tgohle · 0 comments
Owner

Problem

human_to_eng() can interpret values such as 1.5 MHz incorrectly because the old strip order removes hz before suffix matching.

Current code

t = s.strip().lower().replace("vpp", "").replace("v", "")
t = t.replace("hz", "").replace("deg", "")

Why this is a bug

With the old logic, 1.5 MHz becomes 1.5 m before suffix evaluation.

That can result in m being interpreted as milli instead of MHz being interpreted as mega, which sends a completely wrong numeric value to the instrument.

Example

1.5 MHz should become:

1500000

With the old parser it could be interpreted as milli-scale instead.

Fix approach

Replace the strip-and-guess logic with a regex-based parser that reads numeric value and suffix in one pass, using longest suffix match first.

This avoids mhz collapsing into m and makes unit handling much more robust.

Status

Local fix already implemented in the current v0.2 working copy.
Still needs commit, push, and hardware verification before closing.

### Problem `human_to_eng()` can interpret values such as `1.5 MHz` incorrectly because the old strip order removes `hz` before suffix matching. ### Current code ```python t = s.strip().lower().replace("vpp", "").replace("v", "") t = t.replace("hz", "").replace("deg", "") ``` ### Why this is a bug With the old logic, `1.5 MHz` becomes `1.5 m` before suffix evaluation. That can result in `m` being interpreted as milli instead of `MHz` being interpreted as mega, which sends a completely wrong numeric value to the instrument. ### Example `1.5 MHz` should become: ```text 1500000 ``` With the old parser it could be interpreted as milli-scale instead. ### Fix approach Replace the strip-and-guess logic with a regex-based parser that reads numeric value and suffix in one pass, using longest suffix match first. This avoids `mhz` collapsing into `m` and makes unit handling much more robust. ### Status Local fix already implemented in the current v0.2 working copy. Still needs commit, push, and hardware verification before closing.
tgohle added the
area/arb
label 2026-04-17 11:41:04 +00:00
tgohle added the
kind
bug
1
severity
high
1
state
needs-test
1
labels 2026-04-17 11:43:46 +00:00
tgohle added this to the v0.2.0 - first bugfix round finished milestone 2026-04-17 12:08:10 +00:00
tgohle self-assigned this 2026-04-17 12:09:10 +00:00
tgohle removed their assignment 2026-04-17 12:09:17 +00:00
tgohle self-assigned this 2026-04-17 12:09:23 +00:00
tgohle changed title from human_to_eng() parses MHz incorrectly to [Bug]: human_to_eng() parses MHz incorrectly 2026-04-18 11:21:43 +00:00
Sign in to join this conversation.
No description provided.