Skip to content

pint does not parse well unit with exponents #63

@rcaneill

Description

@rcaneill

Some units consists of multiple set of parenthesis, with exponents -1 (e.g. next line). However they are not parsed correctly by pint.

"units": "(kg/m^3)(g/kg)^-1",

import cf_xarray.units  # must be imported before pint_xarray
import pint_xarray
from pint_xarray import unit_registry as ureg

ureg('(kg/m^3)*(g/kg)^-1')

outputs (what we want):

1.0 kilogram2/(gram meter3)

but without the star

ureg('(kg/m^3)(g/kg)^-1')

output

1.0 meter3/gram

I opened an issue in pint about this: hgrecco/pint#1730. In the meantime, we should replace these unit with either a '*' between the parenthesis, or with an extra set of parenthesis.
Any opinion on which solution we should implement?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions