Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resistor Tolerance calculation code throws errors on non integer percentages #447

Closed
tlalexander opened this issue May 26, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@tlalexander
Copy link

I specified some 0.1% resistors and this caused output to fail due to a ValueError thrown from this line:

https://github.com/INTI-CMNB/KiBot/blob/eb6c2140f218f88222cfc5878f322c3a00e8115a/kibot/bom/electro_grammar.py#LL72C6-L72C6

The code tries to cast the value to both a float and an int, and then checks if they are equal. However if the value is actually a float, then casting to an int will throw a ValueError.

I changed the function to the following and it works now:

    def value1(self, d, type):
        """ VALUE """
        v = float(d[0])
        try:
            iv = int(d[0])
            if iv == v:
                v = iv
        except ValueError:
            pass
        self.parsed[type] = v
        return v

I suspect that there is a better way to determine the correct value of v, but this fix was sufficient to get things working.

@krasin
Copy link

krasin commented May 26, 2023

(I am not affiliated with KiBot)

Good catch. One option to make it simpler is:

v = float(d[0])
iv = round(v)
if iv == v:
  v = iv

(I hope I don't miss something obvious here!)

@set-soft
Copy link
Member

Hi @tlalexander and @krasin !
Thanks for looking at the code!
@tlalexander solution is really pythonic, but @krasin solution is simpler.
I'm applying the second, which passes the tests, including a new one for 0.1%

set-soft added a commit that referenced this issue May 29, 2023
@set-soft set-soft self-assigned this May 29, 2023
@set-soft set-soft added the bug Something isn't working label May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants