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

Pretty printing of degrees #546

Closed
dopplershift opened this issue Aug 17, 2017 · 4 comments
Closed

Pretty printing of degrees #546

dopplershift opened this issue Aug 17, 2017 · 4 comments

Comments

@dopplershift
Copy link
Contributor

It'd be nice if degreed units (Celsius, Fahrenheit, angles) would pretty print e.g.

'°F'

rather than

'degF'

Is this technically feasible? If someone can point me in the general direction, I'd be happy to put in a PR.

@hgrecco
Copy link
Owner

hgrecco commented Aug 19, 2017

That indeed would be nice. Typically this is done by replacing the first alias (the string after the second equal) for the desired definition in the definition file. But this is not entirely correct.

The issue is that we do not distinguish now between a short form of a unit (which is stored in symbol of a definition object) and the pretty printed form. But I would be happy to move in this direction.

We would need:
1.- Modify the Definition class to accept long and short form for pretty versions
2.- A spec for unit/prefix definition that can be easily parsed
3.- A good fallback rule when the pretty form is not there
4.- Modify the pretty print algorithm to use them

I can assist if somebody wants to push this forward.

cpascual pushed a commit to cpascual/taurus that referenced this issue Nov 20, 2019
Make celsius display as "°C" in taurus. Do it by registering a new
unit (degreeC) equivalent to degC in taurus.core.units.UR
This is a workaround until pint properly supports this. See:
hgrecco/pint#546
@cpascual
Copy link
Contributor

Hi, I am doing the following workaround in my code in order to support both °C and °C for celsius, and to display °C for celsius. It seems to work for me, but I am not so sure about its correctness.

UR.define(u'degreeC = kelvin; offset: 273.15  = °C = ºC = degC = celsius')

Any comment/suggestion? Something that may backfire and I should be aware of?

Also, are there any plans in supporting this properly in pint?

@hgrecco
Copy link
Owner

hgrecco commented Nov 20, 2019

it seems ok to me.

@jules-ch
Copy link
Collaborator

Closed in #811

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

No branches or pull requests

4 participants