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

Implement Quantity.to_no_prefix for stripping SI-prefix #1373

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nikosavola
Copy link
Contributor

  • Executed pre-commit run --all-files with no errors
  • The change is fully covered by automated unit tests
  • Documented in docs/ as appropriate
  • Added an entry to the CHANGES file

This PR adds a method for Quantity to return a copy with no SI-prefixes, e.g., nanometers to meters w/o specifying that meters are the desired unit.

import pint
Q_ = pint.Quantity
(Q_('8 um')).to_no_prefix()

returns

<Quantity(8e-6, 'meter')>

@hgrecco
Copy link
Owner

hgrecco commented Aug 20, 2021

I think the implementation still needs work. Converting to a string and then replacing by "" is fragile. It would be better to iterate over units, parse each individually and then remove the prefix. Take a look at the Unit api.

@jules-ch
Copy link
Collaborator

I agree with @hgrecco, there is already a function that provides parsing of prefix and units. I'll provide a better review soon.
Difficult for me to provide a review at the moment.

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

Successfully merging this pull request may close these issues.

None yet

3 participants