`divide by zero encountered in double_scalars` when converting units using `equivalencies`
See original GitHub issueDescription
Converting wavelength to frequency using equivalencies
returns a warning if the wavelength is zero.
/home/atharva/miniconda3/envs/astropy-test/lib/python3.9/site-packages/astropy/units/equivalencies.py:126: RuntimeWarning: divide by zero encountered in double_scalars
(si.m, si.Hz, lambda x: _si.c.value / x),
Expected behavior
The code returns inf Hz
, but with the warning, which it shouldn’t.
Steps to Reproduce
import astropy.units as u
a = 0* u.AA
a = a.to(u.Hz, equivalencies=u.spectral())
print(a)
Returns:
/home/atharva/miniconda3/envs/astropy-test/lib/python3.9/site-packages/astropy/units/equivalencies.py:126: RuntimeWarning: divide by zero encountered in double_scalars
(si.m, si.Hz, lambda x: _si.c.value / x),
inf Hz
Any other value apart from zero doesn’t cause the warning.
import astropy.units as u
import math
a = math.inf* u.AA
a = a.to(u.Hz, equivalencies=u.spectral())
print(a) # 0.0 Hz
System Details
Linux-5.8.0-55-generic-x86_64-with-glibc2.29
Python 3.8.10 (default, Jun 2 2021, 10:49:15)
[GCC 9.4.0]
Numpy 1.21.2
astropy 5.0.dev828+g23404eeb2
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
divide by zero using quantity and masked array #7365 - GitHub
When dividing a quantity by a masked array with zeros, this invalid behavior occurs: a = 1e18 * u.m b = np.ma.array([0.,0]) print...
Read more >How to fix 'RuntimeWarning: divide by zero encountered in ...
I found it might be problem with float values, but im not sure about it and im typing it here for looking yours...
Read more >Converting Units using Multiple Conversion Factors - YouTube
To see all my Chemistry videos, check outhttp://socratic.org/chemistryHow do you use more than one conversion factor?
Read more >Conversion of Customary Units by Dividing ( Read ) - CK-12
Use multiplication and division to convert between customary units of length, weight and capacity.
Read more >runtimewarning: invalid value encountered in double_scalars
This tutorial explains how to fix the following error in Python: runtimewarning: invalid value encountered in double_scalars.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@pllim is right - we’re just propagating the numpy warning here, and I think that is probably the best thing to do, since it is quite likely to be a bug if the wavelength is zero.
That is not to say one could not have decided otherwise, and it is always good to think about these issues, so still good to report if something does not feel logical!
Hi humans 👋 - this issue was labeled as Close? approximately 13 hours ago. If you think this issue should not be closed, a maintainer should remove the Close? label - otherwise, I will close this issue in 7 days.
If you believe I commented on this issue incorrectly, please report this here