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

contextualize conversions #49

Closed
tcurdt opened this issue Nov 7, 2018 · 3 comments
Closed

contextualize conversions #49

tcurdt opened this issue Nov 7, 2018 · 3 comments

Comments

@tcurdt
Copy link

tcurdt commented Nov 7, 2018

The problem is that pint uses distinct mapping while in reality there is some kind of ambiguity without a proper context.

For example: Does kn means kilo newton or knots? Does h mean hour or the Planck constant?

It would be great to evaluate the possible meaning of the source expression and the target expression. If there is a match in types it's very likely that's the context the user meant. Or even show the result of both if possible.

No way in hell I will remember I have to use kpm for km/h or knots instead of kn. It's hard to build up muscle memory for this.

I guess replacing the dictionary with units that I use could be an option. But so far I only found how to add new units. No problem to drop the Planck constant. But it would be sad to drop newton.

@tcurdt
Copy link
Author

tcurdt commented Nov 7, 2018

hgrecco/pint#719

@deanishe
Copy link
Owner

deanishe commented Nov 8, 2018

But so far I only found how to add new units. No problem to drop the Planck constant.

Your custom definitions are loaded last and override any built-ins, so you can redefine h as hour.

I guess replacing the dictionary with units that I use could be an option.

You can change the built-in definitions by editing the defaults_en.txt file in the pint subdirectory of the workflow. If you do, keep a copy of your changes, as they'll be overwritten by a workflow update.

For example: Does kn means kilo newton or knots?

Neither. kt is the abbreviation Pint defines for knots. You can also add kn to your custom definitions. Kilonewtons is kN (Pint is case sensitive).

some kind of ambiguity without a proper context

The workflow supports Pint's contexts (just enter the context name first before any numbers).

Fundamentally, the workflow is just a dumb frontend to Pint, and not intended to be much more than that.

Guessing which units are meant from context is something that would have to be implemented by Pint.

@tcurdt
Copy link
Author

tcurdt commented Nov 8, 2018

FWIW: The ISO Standard symbol for the knot is kn. Also see https://en.wikipedia.org/wiki/Knot_(unit)
The same symbol is preferred by the IEEE - but kt is also common.

I didn't know Pint is case sensitive. Good to know!

I have updated the unit_definitions.txt and added

kn = knot
h = hour

and that seems to do the trick for me.

@tcurdt tcurdt closed this as completed Nov 8, 2018
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