`np.float64(np.nan) % 1` gives warning
See original GitHub issueThe following operations correctly return nan
without warning:
import numpy as np
np.nan + 1
np.nan - 1
np.nan * 1
np.nan / 1
np.nan % 1
So do
np.float64(np.nan) + 1
np.float64(np.nan) - 1
np.float64(np.nan) * 1
np.float64(np.nan) / 1
Taking %
, however, does give a warning:
np.float64(np.nan) % 1
<ipython-input-49-4b0062698971>:1: RuntimeWarning: invalid value encountered in double_scalars
np.float64(np.nan) % 1
This inconsistency extends to all numpy float types.
Issue Analytics
- State:
- Created 3 years ago
- Comments:15 (14 by maintainers)
Top Results From Across the Web
Why do negative numpy.float64 yield nan when expontiated ...
A negative numpy.float64 exponentiated with a fractional (i.e., decimal, i.e., rational) number will yield a nan result and a warning.
Read more >data type conversion of numpy array containing NaN #21364
I am working on floating FPEs given by the CPU/C for these casts, so at least most should give an "invalid value" warning...
Read more >Working with missing data - Pandas
Warning. One has to be mindful that in Python (and NumPy), the nan's don't compare equal, but None's do. Note that pandas/NumPy uses...
Read more >NumPy 1.21.0 Release Notes
A deprecation warning will now be issued whenever getting np.typeDict . ... will give a FutureWarning that it will return an object array...
Read more >pandas.DataFrame.mean() Examples
Provides a way to calculate mean on column axis. ... import pandas as pd import numpy as np technologies = ({ 'Courses':["Spark",np.nan ......
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 Free
Top 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
@seberg Yes of course. It’s my first contribution to Numpy and after all the hours I want to finish the job properly. I didn’t enter in the
.src
files because I thought it was for Windows SO only…I have done similar changes to the file to avoid the warning and I get to avoid with NaN as a second input. Right now I will do:
np.inf
to avoid also the error with this constant.Thank you very much for your help.
@arubiales if the warning is actually manually set, it would be something like
npy_set_floatstatus
. But most likely the opposite is the case: The C code (machine code), sets an error flag (the CPU does this, or well, the basic math library) for a certain operation. And our code would have to avoid taking that code path alltogether.