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

Support sq as a prefix representing ** 2 #2062

Open
rob-levy-minimum opened this issue Oct 17, 2024 · 1 comment
Open

Support sq as a prefix representing ** 2 #2062

rob-levy-minimum opened this issue Oct 17, 2024 · 1 comment

Comments

@rob-levy-minimum
Copy link

Pint ships with some "specialized" US area units like square_foot. When I discovered that there was an alias for this of sq_ft I thought that maybe sq might be a recognised prefix representing "square".

I was sad to find that sqm or sq_m doesn't exist. Given that sq_ft does exist in pint this seems like an anomaly.

We often use Pint to parse user-submitted data and our users think of "square metres" as "sqm".

Would it be possible for Pint to understand sqX to mean X ** 2? So, for example, sqcm or sq_cm would also be supported.

@andrewgsavage
Copy link
Collaborator

you can add sqm and others as definitions and aliases to default_en.txt. A PR adding these is welcomed.

I can see some difficulty in getting the parser to understand that the prefix changes the dimensionality (atm prefixes are only numerical multipliers), and with the formatting code. Therefore I don't think it's worth writing something to handle sq as an extra prefix

another option is to use a preprocessor to convert the string 'sq_cm' to 'cm ** 2' https://pint.readthedocs.io/en/stable/api/facets.html#pint.facets.plain.GenericPlainRegistry
This isn't documented yet - it would make a nice example.

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

2 participants