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

Cant simplify electrical units as expected (S*Ω) #747

Open
LKuhrmann opened this issue Nov 4, 2024 · 2 comments
Open

Cant simplify electrical units as expected (S*Ω) #747

LKuhrmann opened this issue Nov 4, 2024 · 2 comments

Comments

@LKuhrmann
Copy link

Hi all, I hope this is not a repeat question.

I am trying to do an operation equivalent to this, but it does not work:
uconvert(u"1/km", 1.0u"S" * 1.0u"Ω" * 1.0u"1/km")

MethodError: no method matching uconvert(::Unitful.Quantity{Int64, 𝐋^-1, Unitful.FreeUnits{(km^-1,), 𝐋^-1, nothing}}, ::Unitful.Quantity{Float64, 𝐋^-1, Unitful.FreeUnits{(km^-1, Ω, S), 𝐋^-1, nothing}})

However, similar situations where units cancel each other out work just fine:
uconvert(u"Ω/km",1.0*u"1/km" * 1.0u"V"/1.0u"A")

1.0 Ω km^-1

Is this a bug or am I misunderstanding what this package can do? Should I be using a different function?

Thanks!

@sostock
Copy link
Collaborator

sostock commented Nov 5, 2024

This doesn’t work because u"1/km" is a quantity, not a unit. You can use u"km^-1" instead.

Duplicate of #720.

@LKuhrmann
Copy link
Author

I see, that wasn't obvious to me. I thought only if there is something before the u Unitful creates a quantity, but I misunderstood.

Maybe an Error message like "Can not unconvert a quantity to another quantity, only to a unit." would be helpful?
In my opinion the current error message is not intuitive.

Maybe somthing like the following could be added to uconvert in conversion.jl:

function uconvert(x::Quantity{T,D,U}, y::Quantity{T,D,U}) 
    error("Can not unconvert a quantity to another quantity, only to a unit.")
end

What do you think?
Either way, thanks a lot for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants