-
Notifications
You must be signed in to change notification settings - Fork 113
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
Update Unitful.uparse() #639
base: master
Are you sure you want to change the base?
Conversation
Nevertheless expanded pkg of Unitful.jl (i.e., UnitfulAtomic.jl) execute Unitful.register(), Unitful.uparse did not recognize these pkgs automaticaly (due to the defaut value of unit_context arg is Unitful only). This commit modified this issue.
@@ -657,12 +657,12 @@ julia> uparse("1.0*dB") | |||
1.0 dB | |||
``` | |||
""" | |||
function uparse(str; unit_context=Unitful) | |||
function uparse(str; unit_context=vcat(Unitful, Unitful.unitmodules)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for this change, I just spent way too long trying to figure out why the imported unit was not parsing, the error message of lookup_units also was not super helpful
IMO, this is a good change.
We could think about this, but I would rather keep the number of allowed functions small. If
I don’t see how this is useful. Where would a “nested” unit string appear? |
Thank you for your feedback.
Hmmm, that may be true. If
Yes I want use the nested unit sting. When saving a number with units, it may be converted to a macro and then written out as a string. |
1 default value of unit_context argument
Nevertheless, expanded pkg of Unitful.jl (i.e., UnitfulAtomic.jl) execute Unitful.register(), Unitful.uparse did not recognize these pkgs automatically (due to the defaut value of unit_context arg is Unitful only).
This commit modified this issue.
2 allowed_funcs
To enable parsing some strings such as "(1:10)m", I added
:colon
and:(:)
.3 parsing macro call
To enable parsing some strings such as "u"m/s"" (unit string including @u_str macro), I added some code in uparse content