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

pint-convert fails with uncertainties related error if numpy is not installed as well - document numpy dependence or give a better error message #2016

Closed
doronbehar opened this issue Jun 15, 2024 · 13 comments · Fixed by #2032

Comments

@doronbehar
Copy link
Contributor

I'm experiencing the following error when trying out the pint-convert executable:

$ pint-convert '32 m/s' 'mile/hour'
Traceback (most recent call last):
  File "/nix/store/c46r9a4x6c67dwr7mb0l6d00apb723l2-python3.11-pint-0.24/bin/.pint-convert-wrapped", line 6, in <module>
    from pint.pint_convert import main
  File "/nix/store/c46r9a4x6c67dwr7mb0l6d00apb723l2-python3.11-pint-0.24/lib/python3.11/site-packages/pint/pint_convert.py", line 106, in <module>
    (R_i, g_e, m_u, m_e, m_p, m_n) = uncertainties.correlated_values_norm(
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'uncertainties' has no attribute 'correlated_values_norm'

My uncertainties version is 3.2.1 - upstream's latest. I also experienced this error with uncertainties 3.1.7. The uncertainties version should ideally be specified in pyproject.toml.

@andrewgsavage
Copy link
Collaborator

try pint-convert 32m/s mile/hour

@doronbehar
Copy link
Contributor Author

try pint-convert 32m/s mile/hour

Same error.

@andrewgsavage
Copy link
Collaborator

andrewgsavage commented Jun 22, 2024 via email

@doronbehar
Copy link
Contributor Author

do you have uncertainties installed?

Yes. I wrote that in the initial bug report, and I mentioned I tried with different versions of uncertainties. Please read thoroughly.

@andrewgsavage
Copy link
Collaborator

sorry I mean does it show when you load python and import uncertainties?

I got that error until I had installed uncertainties

@doronbehar
Copy link
Contributor Author

sorry I mean does it show when you load python and import uncertainties?

I appreciate your effort to help out, but you'll need to trust me, it's not the first time I'm playing with Python packages and installations. In NixOS we don't run exactly "install" packages, but that's out of topic for this discussion. For the sake of the discussion, trust me, I have uncertainties "installed".

Note also the error I quoted in the initial bug report:

AttributeError: module 'uncertainties' has no attribute 'correlated_values_norm'

This means the uncertainties is installed - otherwise there would have been a ModuleNotFoundError instead.

I got that error until I had installed uncertainties

It would be interesting to know which uncertainties version do you have installed.

@andrewgsavage
Copy link
Collaborator

ahh it'll be because you don't have numpy in that env

@doronbehar doronbehar changed the title pint-convert fails with uncertainties related error pint-convert fails with uncertainties related error if numpy is not installed as well - document numpy dependence or give a better error message Jun 22, 2024
@doronbehar
Copy link
Contributor Author

OK That worked. Thanks! It would have been nice if this was documented or if the error message would have been better. I updated the title of the issue to reflect that.

@daspk04
Copy link
Contributor

daspk04 commented Jun 27, 2024

I got some issues while using pint-convert by default, but adding uncertainties package from Nixpkgs worked for me.

Nixos : 24.05
Python: 3.12
uncertainties: 3.1.7
Pint: 0.23

command without uncertainties (worked for me):

pint-convert '32 m/s' 'mile/hour' -U

In my opinion -U should be set as True by default or changed name to --with-unc. Incase one explicitly needs uncertainties, they should explicitly pass command --with-unc and install the optional dependency i.e. uncertainties.

@andrewgsavage
Copy link
Collaborator

yes that would be better. PRs are welcomed

@doronbehar
Copy link
Contributor Author

In my opinion -U should be set as True by default or changed name to --with-unc. Incase one explicitly needs uncertainties, they should explicitly pass command --with-unc and install the optional dependency i.e. uncertainties.

I have a better idea: If there are no indications in the command line arguments that uncertainties should be calculated, then uncertainties shouldn't even be loaded - so there won't be such an error in case it is not even installed. A nicer message suggesting the user to install uncertainties and numpy should be printed in case the command line arguments do require it.

Specifically for you @Pratyush1991 , a Nix specific PR that fixes this experience is available at NixOS/nixpkgs#320113 . Your review and 👍 will be most welcome.

@daspk04
Copy link
Contributor

daspk04 commented Jul 6, 2024

yes that would be better. PRs are welcomed

Thanks @andrewgsavage ! I have added it #2032

@daspk04
Copy link
Contributor

daspk04 commented Jul 6, 2024

In my opinion -U should be set as True by default or changed name to --with-unc. Incase one explicitly needs uncertainties, they should explicitly pass command --with-unc and install the optional dependency i.e. uncertainties.

I have a better idea: If there are no indications in the command line arguments that uncertainties should be calculated, then uncertainties shouldn't even be loaded - so there won't be such an error in case it is not even installed. A nicer message suggesting the user to install uncertainties and numpy should be printed in case the command line arguments do require it.

Specifically for you @Pratyush1991 , a Nix specific PR that fixes this experience is available at NixOS/nixpkgs#320113 . Your review and 👍 will be most welcome.

Thanks @doronbehar! Seems the PR for Nix has been merged which is nice. Btw if this PR #2032 is merged then probably uncertainties package won't be needed in the propagatedBuildInputs , possibly can be an optional package flag for pint package in nix ?

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 a pull request may close this issue.

3 participants